Code:
#!/bin/sh
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
# List of databases to be backed up separated by space
dblist="drupal itreservations moodle mysql"
# Directory for backups
backupdir=/path/to/directroy #edit
# Number of versions to keep
numversions=4
# Full path for MySQL hotcopy command
hotcopycmd=/usr/bin/mysqlhotcopy
# MySQL Username and password
userpassword=" --user=root --password=password"
# Create directory if needed
/bin/mkdir -p ${backupdir}
if [ ! -d ${backupdir} ]
then
/bin/echo "Invalid directory: ${backupdir}"
exit 1
fi
# Hotcopy begins here
echo "Hotcopying MySQL Databases..."
RC=0
for database in $dblist
do
/bin/echo "Hotcopying $database ..."
$hotcopycmd $userpassword $database ${backupdir}
RC=$?
if [ $RC -gt 0 ]
then
break;
fi
# Rollover the backup directories
i=$numversions
/bin/mv ${backupdir}/${database} ${backupdir}/${database}.0 2> /dev/null
/bin/rm -fr ${backupdir}/${database}.$i 2> /dev/null
while [ $i -gt 0 ]
do
/bin/mv ${backupdir}/${database}.`expr $i - 1` ${backupdir}/${database}.$i 2> /dev/null
i=`expr $i - 1`
done
done
if [ $RC -gt 0 ]
then
/bin/echo "MySQL Hotcopy failed!"
exit $RC
else
# Hotcopy is complete. List the backup versions!
/bin/ls -l ${backupdir}
/bin/echo "MySQL Hotcopy is complete!"
fi
exit 0 the above script will do the mysql backup (hotcopy) edit paths, passwords and database names to your requirements. to copy things just add something along the lines Code:
/usr/bin/rsync -avrlHKpogDt /var/www/ /backup/path
or cp -a to keep things simple
for date time thing something like Code:
#!/bin/bash
time=`/bin/date +%Y-%m-%d`
backup_dir=/backup/$time
/bin/mkdir -p $backup_dir
/bin/tar zcvf $backup_dir/backup.tar.gz /backup/ 2&> /dev/null
# to remove any backup older that 14 days
/usr/bin/find /backup -type d -mtime +14 -exec /bin/rm -rf {} \; hope theres something useful in there
personally I use rsync to back up the servers to remote boxes rather than ftp