backup-manager是一个用linux shell编写的命令行备份工具,支持文件及MySQL备份,MySQL备份使用的是mysqldump方式,对于个人站长基本够用了。

貌似它网站在:https://github.com/sukria/Backup-Manager

再加上rsync进行远程的备份数据同步,那就更好了,最起码有一个异地备份。

安装配置Backup Manager

安装

apt-get install backup-manager

配置

配置文件位置:/etc/backup-manager.conf

指定备份文件位置

export BM_REPOSITORY_ROOT="/var/archives/daily"

定义备份任务

export BM_ARCHIVE_METHOD="tarball mysql"

定义备份任务tarball的内容

export BM_TARBALL_DIRECTORIES="/etc /home"

定义MySQL备份内容

##############################################################
# Backup method: MYSQl
#############################################################

# This method is dedicated to MySQL databases.
# You should not use the tarball method for backing up database
# directories or you may have corrupted archives.
# Enter here the list of databases to backup.
# Wildcard: __ALL__ (will dump all the databases in one archive)
export BM_MYSQL_DATABASES="__ALL__"

# The best way to produce MySQL dump is done by using the "--opt" switch 
# of mysqldump. This make the dump directly usable with mysql (add the drop table
# statements), lock the tables during the dump and other things.
# This is recommended for full-clean-safe backups, but needs a 
# privileged user (for the lock permissions).
export BM_MYSQL_SAFEDUMPS="true"

# The user who is allowed to read every databases filled in BM_MYSQL_DATABASES
export BM_MYSQL_ADMINLOGIN="root"

# its password
export BM_MYSQL_ADMINPASS="mypassword"

# the host where the database is
export BM_MYSQL_HOST="localhost"

# the port where MySQL listen to on the host
export BM_MYSQL_PORT="3306"

# which compression format to use? (gzip or bzip2)
export BM_MYSQL_FILETYPE="bzip2"

还可以将备份文件上传到其他位置,目前支持:ftp、s3、rsync、ssh-gpg、scp。

运行

可以在crontab中指定

# m h  dom mon dow   command
0 2 * * * /usr/sbin/backup-manager

使用rsync进行远程同步

再远程备份机器上使用rsync将服务器备份好的数据同步到本地,保留一个异地数据备份,防止灾难发生。

配置SSH自动登录

生成用户密钥

# ssh-keygen -t rsa -C "Jilili's Key"

将公钥发送到服务器,这样下次再登录时就不用输入密码了

cat ~/.ssh/id_rsa.pub | ssh root@cn1.ideais.net "cat - >> ~/.ssh/authorized_keys"

编写同步脚本和建立自动任务

编辑同步脚本,将远程的/opt/和/var/archives/同步到备份设备

$ vi sync-vps-cn1.sh
/usr/local/bin/rsync -avlR --delete -e ssh root@cn1.ideais.net:/opt/ /home/jilili/Mirrors/data/cn1.ideais.net/
/usr/local/bin/rsync -avlR --delete -e ssh root@cn1.ideais.net:/var/archives/ /home/jilili/Mirrors/data/cn1.ideais.net/

把脚本加入系统任务调度

$ crontab -e
0 4 * * * /home/jilili/Mirrors/bin/sync-vps-cn1.sh

相关文章

· backup-manager

[ 编辑 | 历史 ]
最近由“jilili”在“2014-03-19 14:57:36”修改