View Full Version : Full Backup: Daily
kenzie
10-26-2006, 01:24 PM
Is it possible to add a variable (such as day of the week) to the Local Path for daily backups?
i.e. Local path: /root/backups/%day_of_the_week%/
That way I'd have a daily backup for each of the last 7 days. Maybe there's a better way to do this, but I'd like to keep it within Server CP.
Jeremy
10-27-2006, 02:19 AM
Yea i asked about that as well.
But for now..
#!/bin/bash
DIRS="/etc /home"
BACKUP=/tmp/backup.$$
NOW=$(date +"%d-%m-%Y")
INCFILE="/root/tar-inc-backup.dat"
MUSER="root"
MPASS="mysqlrootpasswordhere"
MHOST="localhost"
MYSQL="/usr/bin/mysql"
MYSQLDUMP="/usr/bin/mysqldump"
GZIP="/bin/gzip"
FTPD="//incremental"
FTPU="UsErNamE"
FTPP="PAssword"
FTPS="SERVERnameOFftpserver"
NCFTP="/usr/local/bin/ncftpput"
EMAILID="email@email.com"
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
if [ "$DAY" == "$FULLBACKUP" ]; then
FTPD="//full"
FILE="fs-full-$NOW.tar.gz"
tar -zcvf $BACKUP/$FILE $DIRS
fi
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
FILE=$BACKUP/mysql-$db.$NOW-$(date +"%T").gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done
/usr/local/bin/ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF
mkdir $FTPD
mkdir $FTPD/$NOW
cd $FTPD/$NOW
lcd $BACKUP
mput *
quit
EOF
if [ "$?" == "0" ]; then
rm -rf $BACKUP*
else
echo "Date: $(date)">$T
echo "Hostname: $(hostname)" >>$T
echo "Backup failed"
mail -s "BACKUP FAILED" "$EMAILID" <$T
rm -f $T
fi
It works for me but it doesnt compress each users dir just the whole folder it self. ;)
BTW you will need to install/compile ncftp client to use this.
vBulletin v3.5.1, Copyright ©2000-2010, Jelsoft Enterprises Ltd.