4 ## ## this script handles the daily rotating mongodb backup task for the finalsclub project
5 ## 30 0 * * * /home/ec2-user/fc/fcbackups/fc_rotating_db_backup.sh > /home/ec2-user/fc/fcbackups/cron_log.txt
7 ## this script is dependent on the cp2s3 script
8 ## http://devblog.famundo.com/articles/2007/03/12/cp2s3-a-command-line-smart-copy-script-into-s3
9 ## assumes you've installed ruby and ruby gems.
10 ## sudo yum install ruby
11 ## sudo yum install rubygems
12 ## Installing cp2se requires the installation of the AWS::S3 Ruby library, easiers done with
13 ## sudo gem install aws-s3
14 ## sudo cp cp2s3.rb /usr/bin/cp2s3
16 ## cp2s3 -v -b finalsclub.org_db_backups -r test.txt
19 ## save the current working dir
23 ## this scripts expects these vars to be set
24 ## export AWS_ACCESS_KEY_ID=<YOUR_AWS_ACCESS_KEY_ID>
25 ## export AWS_SECRET_ACCESS_KEY=<YOUR_AWS_SECRET_ACCESS_KEY>
26 if test -e .fcbackup.env ; then
31 bucket="finalsclub.org_db_backups"
32 curdate=`date +"%Y-%m-%d"`
33 yearlydate=`date +"%Y-__-__"`
34 monthlydate=`date +"____-%m-__"`
35 dailydate=`date +"____-__-%d"`
36 mongodump=/usr/local/bin/mongodump
38 bakdir=db-backups/$curdate
42 ## create temp backup/dump dir
46 ## do the db dump into the temp date dir
47 $mongodump --host localhost
49 ## create an archive from the dump dir
51 tar czf db-dump_$curdate.tgz $curdate/dump
53 ## clean up by deleting the temp dir
56 ## rename and copy the latest dump archive up to s3, using the yeary, weekly and daily naming conventions
57 mv db-dump_$curdate.tgz db-dump_$yearlydate.tgz
58 cp2s3 -v -b $bucket/yearly -r db-dump_$yearlydate.tgz
60 mv db-dump_$yearlydate.tgz db-dump_$monthlydate.tgz
61 cp2s3 -v -b $bucket/monthly -r db-dump_$monthlydate.tgz
63 mv db-dump_$monthlydate.tgz db-dump_$dailydate.tgz
64 cp2s3 -v -b $bucket/daily -r db-dump_$dailydate.tgz
65 ## NOTE: we are keeping the last 31 daily backups on disk.
67 ## restore previous working dir