Skip to content

Instantly share code, notes, and snippets.

@cldotdev
Created January 22, 2014 08:46
Show Gist options
  • Select an option

  • Save cldotdev/8555458 to your computer and use it in GitHub Desktop.

Select an option

Save cldotdev/8555458 to your computer and use it in GitHub Desktop.
regularly backup data
#!/bin/bash
# Add the path of this file to /etc/crontab
# e.g.
# $ chmod 700 dumpdb; mv dumpdb /etc/cron.daily/
today=$(date +%Y%m%d)
basedir=/var/backups
mysql_password=
if [[ -x /usr/bin/mysqldump ]]; then
mysqldump -u backup -p${mysql_password} --all-databases |xz --best >$basedir/mysql/mysql-${today}.sql.xz
fi
if [[ -d /opt/redmine-2.4.2/files ]]; then
tar -Jcf $basedir/redmine/redmine-files-${today}.tar.xz /opt/redmine-2.4.2/files
if [[ $(ls $basedir/redmine | wc -l) > 30 ]]; then
find $basedir/redmine -name 'redmine-files*' -mtime +30 -exec rm {} \;
fi
fi
# Sync backup files with the remote server
remote_user=
remote_ip=
remote_port=
remote_dir=
ping $remote_ip -c 2
if [[ $? == 0 ]]; then
rsync -aAXv --delete -e "ssh -p $remote_port" $basedir/mysql ${remote_user}@${remote_ip}:${remote_dir}
rsync -aAXv --delete -e "ssh -p $remote_port" $basedir/redmine ${remote_user}@${remote_ip}:${remote_dir}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment