Backup Your CVS/SVN Repository to Amazon S3

Recently I decided to implement one additional layer of protection for our CVS repository. It was only backed up to another folder on the same server,
the same virtual disk (RAID 0). “Why not use Amazon S3 storage for additional protection?”,- I thought.

Step 1: Compile FUSE support into the kernel and install s3fs
Step 2: Mount S3 bucket to a local folder on the server. To achieve this create a file /etc/passwd-s3fs and put your Access Key and Secret Access keyseparated by the colon there.
Step 3: Edit your fstab and put the following line there:
s3fs#your_bucket_name       /mnt/s3_storage       fuse    auto            0 0

This script leaves only the most recent copy of the backup in the BACKUPSDIR and 7 copies (for 7 days in a row) on the remote storage. All backups on the remote storage are encrypted with your password. Don’t forget to change it (–passphrase pwd ). Enjoy!

#!/bin/bash
#
# Back up CVS
#
CVSDIR=/home/cvs
BACKUPSDIR=/home/andrew/backups
S3DIR=/mnt/s3_storage
#
# Get current date and time
set `date +"%Y %m %d %H %M"`

# Remove any backups older than 1 days
echo "Removing backups older than 1 days..."
TO_DELETE=$(find $BACKUPSDIR -atime +1 -name "cvstree*")

if [ -z "$TO_DELETE" ]; then
    echo "No backups to delete"
else
    # remove them!
    rm -f $TO_DELETE
fi

#echo "Backing up CVS tree..."
/bin/tar -cj -C $CVSDIR --totals . > $BACKUPSDIR/cvstree_$1-$2-$3.tar.bz

echo "Encrypting the backup"
/usr/bin/gpg -c --batch --passphrase pwd $BACKUPSDIR/cvstree_$1-$2-$3.tar.bz
echo "Moving to the remote storage"
/usr/bin/mv $BACKUPSDIR/cvstree_$1-$2-$3.tar.bz.gpg $S3DIR

# Remove any backups older than 7 days on the remote storage
echo "Removing backups older than 7 days from the remote storage..."
TO_DELETE=$(find $S3DIR -mtime +7 -name "cvstree*" )

if [ -z "$TO_DELETE" ]; then
    echo "No backups to delete"
else
    # remove them!
    rm -f $TO_DELETE
fi

exit 0

Post a Comment

Your email is never published nor shared. Required fields are marked *