全备
tar zcvf web.tar.gz /path/to/www
简单的备份脚本bak.sh
#!/bin/bash
time=`/bin/date +%F`
bak_file="/data/backup/$time.tar.gz"
webdir="/data/www/"
tar zcvf $bak_file $webdir >/dev/null 2>&1 &
定时执行
[root@letong ~]# crontab -l
#每天晚上23点59执行脚本
59 23 * * * /bin/bash /data/bak.sh
同步备份采用rsync
安装
yum -y install xinetd rsync
配置 /etc/xinetd.d/rsync
disable = no
vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 4 #最大连接
port = 873 #默认端口
[backup]
path = /backup/
comment = "This is a test"
read only = yes
list = no
ignore errors
auth users = letong #加密用户
secrets file = /etc/rsync.pas #加密文件
hosts allow = 0.0.0.0/0 #acl列表
cat /etc/rsync.pas
letong:123456
为了安全期间,只给予属主权限
chmod 600 /etc/rsync.pas
启动
service xinetd start
rsync --daemon
客户端操作
cat /home/rsync.pas
123456
更改权限
chmod 600 /home/rsync.pas
同步命令
rsync -avz --password-file=/home/rsync.pas [email protected]::backup /bakdir
crontab每小时同步一次
0 * * * * rsync -avz --password-file=/home/rsync.pas [email protected]::backup /bakdir