#!/bin/sh # A script to tar and zip your files and databases, and email them off the server. # Requirements: Place this script, export_backups.php, and gdrive directory in # the same directory (see "SCRIPT_DIR" below) # Both the BACKUP_DIR and the SCRIPT_DIR must exist prior to execution, as # I'm too lazy a coder to check ####################################################################################### #### #### CONFIG #### Change as required #### ####################################################################################### #Your hostitnow account name USER_NAME= #Your DB password. Sorry, I couldn't think of a way to encode this DB_PASS= DOMAIN=.com #Directories to backup, relative to your home directory BACKUP_DIRS="public_html scripts mail" #Subdirectories of these directories to exclude, relative to your home directory EXCLUDE_DIRS="public_html/mt public_html/nerds public_html/archives public_html/media public_html/syncml" #DBs to backup. Do not include the "username_" prefix, as in "kevinco_" DBNAMES="blogs phpbb cooney wcln1" ####################################################################################### ### ### SEMI-CONFIG ### You shouldn't need to change anything here, but I guess you can ### ####################################################################################### USER_DIR=/home/$USER_NAME BACKUP_DIR=$USER_DIR/backups #Where the backups will be placed temporarily SCRIPT_DIR=$USER_DIR/scripts #This directory ####################################################################################### ### ### BACKUP SECTION ### No need to change below here ### ####################################################################################### TMP_BACKUP_LIST= cd $USER_DIR; EXCLUDE_LIST= for ex in $EXCLUDE_DIRS do EXCLUDE_LIST="$EXCLUDE_LIST --exclude $ex" done echo "Tarring Files..."; tar -czf $BACKUP_DIR/file_backup.tar.gz $BACKUP_DIRS $EXCLUDE_LIST; TMP_BACKUP_LIST="$TMP_BACKUP_LIST $BACKUP_DIR/file_backup.tar.gz"; echo "Retrieving DB archive..."; for db in `echo $DBNAMES` do wget -q http://$USER_NAME:$DB_PASS@$DOMAIN:2082/getsqlbackup/$db.gz -O $BACKUP_DIR/$db.gz; TMP_BACKUP_LIST="$TMP_BACKUP_LIST $BACKUP_DIR/$db.gz"; done echo "Retrieving email archive..."; EMAIL_FILE=`date +%Y-%B`.txt wget -q http://$DOMAIN/pipermail/ndgang_$DOMAIN/$EMAIL_FILE.gz -O $BACKUP_DIR/email/$EMAIL_FILE.gz #gunzip -f $BACKUP_DIR/email/$EMAIL_FILE.gz tar -cf $BACKUP_DIR/ndgang_email.tar $BACKUP_DIR/email/*.txt.gz TMP_BACKUP_LIST="$TMP_BACKUP_LIST $BACKUP_DIR/ndgang_email.tar" echo "Creating full backup..."; tar -cf $BACKUP_DIR/full_backup.tar $TMP_BACKUP_LIST; rm $TMP_BACKUP_LIST ; echo "Sending backup to Gmail..."; php $SCRIPT_DIR/export_backups.php; rm $BACKUP_DIR/full_backup.tar; echo "Backup complete";