Photos

MFM

Trying to prevent myself from another home fiasco, I’ve decided to build a simple script to backup some of my directories. There are a lot of scripts / backup tools out there, but I just wanted to build my own for the fun of it, and since what I really wanted was to create a tar.gz of the contents of a specific directory (no root path), including hidden files, and without the need to support incremental backups. Take a look at the script:

The complicated part comes from the transform expression, which is used to get rid of the absolute path to the directory we are backing up. The tar –directory option here is not useful since it adds the “.” special path to the packaged file, so let’s break it down:

Leave a Comment

1 Comment to "Simple backup script for Ubuntu"

Hi, here are some tips for you.
You can use other delimiters then ‘/’ in sed. So that if you plan to use slashes in your regex, you don’t need to escape them. I usually delimit with ‘#’ in this case.
So the command to strip trailing slashes becomes this : sed ‘s#/$##’
Note that ‘-e’ is not needed, it’s the default for sed. Also you don’t need the ‘g’ pattern modifier.
Knowing this, you can make your regexes a lot easier

Also check ‘man test’, you’ll see that you can rewrite [ "$1" != "" ] into [ -n "$1" ]

You don’t need to echo “” for a newline, just echo without args, or add “\n” in your previous echo and use the -e flag.

Also you might want to redirect your error messages to stderr.

There is more stuff that can be improved… I suggest you go check out the bash tutorials at tldp.org. they are pretty good