Snippets

Володимир Годяк Backup script site and database to ftp

Created by Володимир Годяк
#!/bin/sh
# Company Otakoyi.com
# Author wmgodyak mailto:wmgodyak@gmail.com

# Config
BACKUP=/var/www/backup
BACKUP_DIR=/var/www/example.com

#MySQL
MUSER="root"
MPASS=""
MDB=""

# FTP
FTPD="/"
FTPU=""
FTPP=""
FTPS=""

# end config

# Binaries
TAR="$(which tar)"
GZIP="$(which gzip)"
FTP="$(which ftp)"

# archive prefix
NOW=$(date +%Y%m%d)
DUMPFILE=full-$NOW.tar.gz

# tmp dir

mkdir $BACKUP/$NOW

# backup site and db to tmp dir

$TAR -czf $BACKUP/$NOW/site.tar.gz $BACKUP_DIR
mysqldump -u$MUSER -p$MPASS $MDB > $BACKUP/$NOW/db.sql

ARCHIVE=$BACKUP/$DUMPFILE
ARCHIVED=$BACKUP/$NOW

# backup all to one archive
$TAR -zcvf $ARCHIVE $ARCHIVED

# ftp
cd $BACKUP
$FTP -np $FTPS <<END_SCRIPT
quote USER $FTPU
quote PASS $FTPP
cd $FTPD
mput $DUMPFILE
quit
END_SCRIPT

### clear ###

rm -rf $ARCHIVED
rm $ARCHIVE

Comments (0)