1

I have automysqlbackup running on Ubuntu 10.04 and it works perfectly fine.
I currently have it performing daily backups for all databases, but I would like to adjust the configuration to do the following:

Perform daily backups of all databases into one folder but as separate .sql files, and then have that folder be a gzip with the timestamp the backup performed.

I was wondering if anyone else has managed to do this, and if so, how could I configure it?

Thanks!

Nina
  • 221
  • 3
  • 7

1 Answers1

2

Got it - I just placed this into cron. Modified a bit based on Jason Tan's answer.

#!/bin/sh
# Find out what databases are in mysql and back them up
# Delete old backups
STARTTIME=` date +%Y%m%d-%H%M `

#BACKUP_DIR="/var/backup/db/data"
BACKUP_DIR="/var/backup/db/data"
LOGFILE="/var/backup/db/data.log"
USER="root"
PASSWD="<password>"
KEEP="20"

(
echo
echo " ---MySQL backups start ${STARTTIME} ---"
#delete any backup written more than ${KEEP} days ago
echo "Removing files over ${KEEP} days old from ${BACKUP_DIR}:"
/usr/bin/find  ${BACKUP_DIR} -mindepth 1 -mtime +${KEEP} -print -delete
echo
echo "Performing today's dumps"
#find each database running in this instance of mysl
for DB in ` echo "show databases;"|mysql -u${USER} -p${PASSWD} mysql |awk " NR>1 {print         
$1} " `
do
    #generate a backup file name based on the data base name
    BACKUP_FILE="${BACKUP_DIR}/${DB}-${STARTTIME}.sql"
    echo "Processing database ${DB} into file ${BACKUP_FILE}"
    # dump the database data/schema into the backup file
    mysqldump -u${USER} -p${PASSWD} ${DB} > ${BACKUP_FILE}
    #gzip ${BACKUP_FILE}
done

ENDTIME=` date +%Y%m%d-%H%M `
echo
echo " ---MySQL backups complete ${ENDTIME} ---"
echo
) >>  ${LOGFILE} 2>&1

ENDTIME2=` date +%Y%m%d-%H%M `
(
#copy backup directory to a new backup directory with end time  

tar -zcvf ${BACKUP_DIR}-${ENDTIME2}.tar.gz ${BACKUP_DIR}
)
Nina
  • 221
  • 3
  • 7