Lets make a killer backup tool

What do you have and what do you want?

Moderators: b1o, jkerr82508

jkerr82508
Guru-Berserk
Posts: 211
Joined: 16 Oct 2010, 21:45
Location: Fife, Scotland

Re: Lets make a killer backup tool

Postby jkerr82508 » 26 Jan 2011, 10:23

When I started trying to write bash scripts, I read somewhere a recommendation always to use the full path to any file (especially executables) used in the script. It may not always be necessary, but it does no harm.

Jim

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Lets make a killer backup tool

Postby viking60 » 26 Jan 2011, 11:56

I use the full path in viking.backup and I have now added the full path to ex.txt. Running it without cron to see if it still works....
And that did hurt :C The exclude list comes up with errors. There is a lot of "relative" stuff regarding rsync.
Installed gnome-schedule to make sure I have not fubared my syntax with spaces etc....
Nope :f I am getting frustrated here so I will now install dropbox.....
Yes that helped :dance: 2 GB ready for unimportant files 8-)
And important ones: :shock:
http://dl.dropbox.com/u/12631335/viking.backup
http://dl.dropbox.com/u/12631335/ex.txt
http://dl.dropbox.com/u/12631335/backup.sh

Hey we can all become friends here and do this together -how very nice :love :cheers
Now where do I put the nude photos of my mistress :think:
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
rolf
Guru-Berserk
Posts: 1107
Joined: 16 Mar 2010, 16:07

Re: Lets make a killer backup tool

Postby rolf » 26 Jan 2011, 16:06

I was thinking along the lines of cron needing to be told what is the working directory, something like:

Code: Select all

#!/bin/bash
cd /home/thomas
for i in `cat viking.backup`;
do rsync -azrvv --delete --delete-excluded  --exclude-from 'ex.txt'  $i /media/My?Book/thomas-pc_backup/;
done


or, alternately

Code: Select all

#!/bin/bash
for i in `cat /home/thomas/viking.backup`;
do rsync -azrvv --delete --delete-excluded  --exclude-from '/home/thomas/ex.txt'  $i /media/My?Book/thomas-pc_backup/;
done


It doesn't look to me that you followed me, there. (one too many Fleinsopp, probably :P )
Whether that's it, idk but there's a lot about cron and path and environment here at google: Image

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Lets make a killer backup tool

Postby viking60 » 26 Jan 2011, 16:55

:Doh: I was to busy playing with Dropbox there. OFCOURSE that works - caramba! Sometimes I just need to make life difficult.
I have been rewriting the script for python for the last hour due to that stupid mistake :liar:
I'll promise you my next pizza will be without Fleinsopp :-D
Your first option works like a charm :gpost :bowlolImage
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
rolf
Guru-Berserk
Posts: 1107
Joined: 16 Mar 2010, 16:07

Re: Lets make a killer backup tool

Postby rolf » 26 Jan 2011, 17:02

Image

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Lets make a killer backup tool

Postby viking60 » 26 Jan 2011, 18:07

:lol: You really know how to pick them.
OK time to sum it up then:
We have a fully functional and flexible backup system that can be set as a cron job (which is a must for backup systems really).
We never have to touch the code in backup.sh after the initial setup. Unless your mount point for the hard disk varies.
We decide what is to be backed up in the file viking.backup and we can easily alter it every time we feel the need for it.
We can pick entire directories for our backup in viking.backup because it now is easy to exclude what we do not want.
We can make a list in the file ex.txt that will be excluded from the backup directories i.e tmp/.
We can exclude directories, files and file patterns.
Backups containing files and directories that later have been excluded are "cleansed", meaning that the old, now excluded files and directories, are deleted on the backup.
I am getting tears in my eyes here - What a success! :B

The files needed to achieve the wonders described above are:
backup.sh

Code: Select all

#!/bin/bash
cd /home/<your_name>
for i in `cat viking.backup`;
do rsync -azrvv --delete --delete-excluded  --exclude-from 'ex.txt'  $i /media/<your_HD>/<your_backup_directory>/;
done

This is the script that makes the magic happen. We need to tell it what to back up in:
viking.backup

Code: Select all

/home/<your_name>
/etc

You can put whatever you want in here as long as you get the syntax right:
/home/<your_name>/ will put the content of your home directory directly in your backup directory.
/home/<your_name> will put the folder with contents in your backup directory
/home/Documents/my_loveletter.txt will put one love letter in your Documents directory on the backup.etc. etc.

After we have backed up the entire home directory we might want to exclude some things we do not need. This can be temp files and cache etc.
We do that in the shape of a list in the file:
ex.txt

Code: Select all

*/tmp
*/.config/gsmartcontrol/*
*/.cache
*/.gvfs

Again this is an example you can exclude whatever you want. With one exception: You must exclude <your_name>/.gvfs if you run the backup as root (sudo or su). Or else the backup will not finish correctly. The effect being that nothing old is deleted on the backup.
In general if you test run the backup and get an error message it makes great sense to put the file on the exclusion list to ensure a smooth backup. +1
If you run a backup as a normal user you might get one or two files or directories that you cannot access. exclude them or chmod them!

Put all the files above in your </home/<your_name>/ directory and you can run it by typing sh backup.sh in your ~/ (home directory).
once you have tuned the lists to your liking you can automate your backup with a cronjob:

Code: Select all

sudo EDITOR=nano crontab -e

and

Code: Select all

15 20 * * * /bin/bash /home/<your_name>/backup.sh

This will start your backup a quarter past 8 pm - every day. (This is a root cronjob because we need to backup /etc)

Obey by these rules from Valhalla and you will live to fight another day :lol:
Puh :coffee_smile:
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Lets make a killer backup tool

Postby viking60 » 26 Jan 2011, 18:39

OK b1o we have the functionality! How about a nice applet or something to make this one fool proof?
Ah my first scheduled backup just started :boohoo: How do I know? Here is a trick: I have excluded the entire tmp directory from the backup so if it exists it will be deleted from the backup.
So i just created a tmp directory on the backup HD. It will be removed (first thing) when the backup starts. :ugeek:
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Lets make a killer backup tool

Postby viking60 » 28 Jan 2011, 02:27

OK I have managed to adapt the script to work with SSH too:

Code: Select all

#!/bin/bash
for i in `cat /home/thomas/viking.backup`;
do rsync -azr --delete --delete-excluded  --exclude-from 'ex.txt' ssh $i thomas@thomas-pc:/media/My?Book/viking60-server_backup/;
done

This is my viking-server connecting to my HD on thomas-pc and backing up.
Here I meet a special challenge because ssh is not to keen to transfer file names with øæå (Norwegian letters). So I figure I have to implement

Code: Select all

LANG=nb_NO.utf8
somewhere. And that is the problem: where should it go?
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
rolf
Guru-Berserk
Posts: 1107
Joined: 16 Mar 2010, 16:07

Re: Lets make a killer backup tool

Postby rolf » 28 Jan 2011, 02:46

I recall some talk about setting environment values in bash scripts popping up at the previous google search, ^^^up there^^^: Image . Look at ->this one<-, also.

Maybe you should put a line at the beginning of your script:

export LC_ALL="nb_NO.utf8"

or

export LANG=nb_NO.utf8

idk :confused just from looking at some of that dialog @ google...

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Lets make a killer backup tool

Postby viking60 » 28 Jan 2011, 12:52

Thanks I'll experiment with the placement. It does not help when putting it on top of the script. The backup runs but the deletion is skiped and the files containing exotic letters come up with errors:

Code: Select all

rsync: recv_generator: failed to stat "/media/My Book/viking60-server_backup/thomas/Dokumenter/atester/s\#370knad GF.doc": Invalid or incomplete multibyte or wide character (84)
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
rolf
Guru-Berserk
Posts: 1107
Joined: 16 Mar 2010, 16:07

Re: Lets make a killer backup tool

Postby rolf » 07 Feb 2011, 17:30

Don't know if you've the time or inclination, FL, but I thought it might be a fit for you to post your killer bash app over here: http://code.google.com/p/universal-bash-script-gui/ :tux5:

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Lets make a killer backup tool

Postby viking60 » 07 Feb 2011, 23:04

Hey great finding!
I am not finished I have made a two python versions - well not even versions but still backups. One of the advantages is that I do not get the ssh lang problem.
I thought I should tidy up the variables a bit with prompting etc. too
And every time I am almost there. Gizmo walks over my keyboard. :naughty: And then I start thinking that the discussion around the script and functions is more important that the fancy inputs in the script.
I will post it over there when I am "finished" :tux5:
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"


Return to “Software”