3 # Bup-DB (alpha v0.10a)
4 # Copyright (C) 2012 FinalsClub Foundation
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # Create a database dump based upon input.
27 # Generate MD5 sum of file
28 function create_hash() {
33 # Verify if file hashes match for verification.
34 function verify_hash() {
36 if [ "`cat $1.md5`" == "`md5sum $1`" ]; then
39 echo "Fail : Backup has not been completed!"
40 # Add measures to ensure that backup is removed and re-attempted.
44 # Make a commit to bup
45 function bup_commit() {
47 bup index -vux $BUP_DIR
48 bup save -vn $USE_CASE $BUP_DIR
51 # Set up our local bup using the backup user.
54 # Create Our Backup Environment on the Server
56 cp -r $WEB_ROOT $BUP_DIR
57 chown -R backup:backup $BUP_DIR
62 # Used if pulling backups from remote server
63 function bup_remote_backup(){
65 echo "Pulling backup from : $BACKUP_SRV"
66 bup on $BACKUP_SRV index -u $BUP_DIR
67 bup on $BACKUP_SRV save -n $USE_CASE $BUP_DIR
71 # General Database backups
74 rsync -r $WEB_ROOT $BUP_DIR/uploads
75 pg_dumpall > $BUP_DIR/$USE_CASE.sql
76 create_hash $BUP_DIR/$USE_CASE.sql
81 #Push snapshot to the S3 bucket
83 tar fcjv /tmp/$USE_CASE-$DATE.tar.bz2 ~/.bup
84 s3cmd put /tmp/$USE_CASE-$DATE.tar.bz2 s3://$BUCKET
87 # Removes old BUP snapshot, still a WIP.
88 function old_bkup_rm() {
89 s3cmd la s3://$BUCKET | cut -d / -f4 | cut -d - -f4 | cut -d . -f1
93 # Display a basic help page / script info.
95 echo "You seem to be lost. This is a pre-alpha of bup-db. Next release"
96 echo "Will be a Python patch for bup"
97 echo "---------------------------------------------------------------"
98 echo " bupdb.sh [-Flags ] "
99 echo "---------------------------------------------------------------"
100 echo " -b bucket_name"
101 echo " -h user@remote_host"
109 function env_check() {
112 while getopts b:h:n:r:w: option
116 b) BUCKET=${OPTARG};;
117 h) BACKUP_SRV=${OPTARG};;
118 r) BUP_DIR=${OPTARG};;
119 n) USE_CASE=${OPTARG};;
120 s) WEB_ROOT=${OPTARG};;