Topic: My backup scripts
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)