You are not logged in.
Pages: 1
I just wanted to share the two scripts I have put together to manage my system backup needs. They have been built from a variety of sources and tailored to my individual needs, obviously YMMV.
The first one does a backup of my /home partition to an SD card in my AspireOne, ignoring media files and a few others:
#!/bin/bash
# Backup /home to SD card
logfile=~/rsync_log.txt
if mountpoint -q /home/marc/backup
then
echo "$(date) Backup Drive is mounted." > $logfile
echo "$(date) Starting script, about to run rysnc" > $logfile
/usr/bin/rsync -a --delete --exclude-from /home/marc/exclude /home/marc /home/marc/backup >> $logfile 2>&1
echo "$(date) returned from rsync call" >> $logfile
else
echo "$(date) Backup Drive not mounted,mounting now." > $logfile
mount /dev/mmcblk0p1 /home/marc/backup
echo "$(date) Backup Drive is mounted." > $logfile
echo "$(date) Starting script, about to run rysnc" > $logfile
/usr/bin/rsync -a --delete --exclude-from /home/marc/exclude /home/marc /home/marc/backup >> $logfile 2>&1
echo "$(date) returned from rsync call" >> $logfile
fi]Its not elegant and can probably be vastly improved and simplified as I am very new at this but it seems to work for me.
The second one does a backup of /, ignoring /home and a few others:
#!/bin/bash
# Backup / to SD card with rsync
logfile=~/tar_rsync_log.txt
if mountpoint -q /home/marc/backup
then
echo "$(date) Backup Drive is mounted." > $logfile
echo "$(date) Starting script, about to run tar/rysnc" > $logfile
#/usr/bin/rsync -a --delete --exclude-from /home/marc/tar_exclude / /storage/backup >> $logfile 2>&1
#/bin/tar cvzpf /home/marc/backup/root_backup.tgz /storage/backup
/bin/tar cvzpf /home/marc/backup/root_backup.tgz --exclude=home --exclude=media --exclude=proc --exclude=locale --exclude=bin/tar --exclude=storage --exlcude=root/.local/share/Trash / >> $logfile 2>&1
echo "$(date) returned from tar/rsync call" >> $logfile
else
echo "$(date) Backup Drive not mounted,mounting now." > $logfile
mount /dev/mmcblk0p1 /home/marc/backup
echo "$(date) Backup Drive is mounted." > $logfile
echo "$(date) Starting script, about to run tar/rysnc" > $logfile
/usr/bin/rsync -a --delete --exclude-from /home/marc/tar_exclude / /storage/backup >> $logfile 2>&1
/bin/tar cvzpf /home/marc/backup/root_backup.tgz /storage/backup
echo "$(date) returned from tar/rsync call" >> $logfile
fiIt is equally as messy as the first, with the added joy of the log file not working, not that that is a big problem for me as it's primary function, the backup, works fine.
I call them both from root's crontab, the first one on the hour and the second one once a week. This way even if my hard drive melts all I need to do is eject the SD card and I can reinstall on a new hard drive and get my customisations and data back sharpish.
Any comments are very welcome, I need to get better at all this and criticism is the only way!
Last edited by badger (2011-06-15 08:52:08)
Offline
looks interesting. especially as we have tried something quite similar a little while ago (is now even feturing a gui as i've just seen!)
my thoughts on your code:
i think the tilde character (~) in the path to the logfile messes it up if you run as root. it will expand to $HOME of the current user and that is not you in this case. try to give a full path. maybe that helps.
is there a reason you give full paths for the commands in your script?
why are you using rsync instead of tar or cp? tar also has an --exclude option. (i do not know rsync so maybe this is obvious, sorry)
Offline
I had not seen that thread before, looks like I have some reading to do!
Thanks for pointing out about the tilde, shows how much I really know about Linux doesnt it!
I only give the full paths to make sure everything works, is there a problem with this or is just unconventional?
I am using rsync as it is differential and so reduces the amount of time each backup takes as it only transfers changed files rather than everything, although I dont know if this actually helps with the tar backup or not. Would I be better off just tar-ing my / with the excludes?
Sorry for not knowing much, this is still very much a learning curve for me!
Offline
incremental backup sounds good.
it might be that it does not help if you use tar afterwards. that is (if I understand rsync correctly) b/c rsync just creates (and maintains incremental) a identical and completely independent file hierarchy at some other point. but if it is exactly the same stuff, there is no need to copy it somewhere before taring it.
this is just what i could figure out and understand (i don't know the options -a --delete) but maybe some rsync-guru can confirm this.
about the commandnames: i think it is just unconventional. it will only break if the user (you) does not have the command at the path you expect it to be. (if somebody does (s)he should be enough of a hacker to fix your script on his/her one)
cheers
luc
Offline
You are right, I have been thinking about it and it does not serve a purpose i the tar backup script, I will remove it. In the first script though it is super quick. Depending on how much work I have done in the last hour (!) it only takes five or sometimes ten minutes to update the backup, much quicker than just doing cp i think.
Offline
LuckyBackup is a nice gui for scheduling rsync backups. One of the most useful features is the ability to test the backup with a "dry run".
"Deja-Dup" also in synaptic is a simple frontend GUI to Duplicity for encrypted local or remote backups.
Last edited by tradetaxfree (2011-07-24 16:54:11)
Offline
Another awesome backup tool is rsnapshot. It does an incremental backup using a set of cron jobs. It uses hardlinks between snapshots to only store changes - I think of it as a linux-style CLI equivalent to Apple's Time Machine.
It is on the standard debian repository, check it out.
If you have noticed this notice you may have noticed that this notice is not worth noticing
Offline
Pages: 1
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.