After a near-disastrous incident with a recent power outage and a large ResierFS partition, I decided to write a handy-dandy backup script to prevent all my stuff from being wiped out. So here's what I've come up with after a bit of digging through some Linux reference books:
And yes, I do know it's ugly as sin.
Code:
#!/bin/sh
#Simple backup script for a few important things
#mount the backup drive and other necessary drives
echo 'Mounting necessary volumes...'
mount /dev/hdd /mnt/backup
mount /boot
echo 'Done'
#set the date for backup names
D='date +"%Y%m%d"'
#copy the necessary files and dirs for backup
echo 'Copying files marked for backup...'
cp -p /usr/src/linux/.config /mnt/backup/tmp
cp -pr /var/cache/edb/ /mnt/backup/tmp
cp -pr /home/neo/ /mnt/backup/tmp
cp -pr /etc/ /mnt/backup/tmp
cp -pr /root/ /mnt/backup/tmp
cp -pr /boot/ /mnt/backup/tmp
echo 'Done'
#compress the tmp dir into a tarball
echo 'Creating tarball now...'
tar cpzf /mnt/backup/system_$D.tgz /mnt/backup/tmp/*
echo 'Done'
#delete the contents of /mnt/backup/tmp
echo 'Cleaning up...'
rm -rf /mnt/backup/tmp/*
echo 'Done'
#unmount the previously mounted drives
echo 'Unmounting drives...'
umount /dev/hdd
umount /boot
echo 'Done'
#...and I'm spent
echo 'Your system is now fully backed up. Hooray!'
Here's the problems I'm currently having:
1. The script refuses to attach the date to the filename. The tarball should be "system_20031207.tgz", however it ends up being "system_date". How can I fix this?
2. What options do I need to give cp to preserve the directories? I want to simply be able to untar the latest backup from my root directory and be ready to go.
3. I've got another Gentoo box I use as a file server. How do I tell the script to automatically upload the latest backup to the server?
4. These backups are likely to take up a lot of space. How can I tell the script to delete older backups?
Any advice, or suggestions on how to improve it, would be greatly appreciated.