Monday, June 22, 2009

Homegrown Ubuntu Backups

sbackup on Ubuntu is a nice backup utility, but I needed to copy my backup files across network to a Windows server with a 1TB external drive formatted in FAT32. What sbackup needed was a way to samba mount my external drive, a way to break up files larger than 4GB, and to breakup the backups into nice size chunks that can be copied nicely over my network.

Here's my quick script to backup my /home dir.

#!/bin/sh

BACKUP_DIR=/home/robert

DATESTAMP=`date '+%Y%m%d'`
echo "Backing up Copernicus laptop..."

ls -1 $BACKUP_DIR | while read dir
do
echo "Backing up $dir"
TARFILENAME="${dir}_${DATESTAMP}"
tar cvpjf /var/backup/local_backups/backup_${TARFILENAME}.tar.bz2 --exclude=*.log --exclude=lost+found $BACKUP_DIR/$dir
split -b4GB /var/backup/local_backups/backup_${TARFILENAME}.tar.bz2
done


sudo smbmount //192.168.0.122/copernicus/backup /mnt/backup -o username=YYY,password=XXX

mkdir -p /mnt/backup/backup_${DATESTAMP}

mv /var/backup/local_backups/backup_*_${DATESTAMP}.tar.bz2* /mnt/backup/backup_${DATESTAMP}
echo "Finished backing up Copernicus laptop..."
exit 0

No comments: