rsync -avz -e ssh bak@192.168.0.138:/home/res /home/res/bak
1. 使用Replication进行实时备份
参考mysql docs
2. 定期在slave上使用shell,mysqldump,sftp,crontab进行永久备份
#!/bin/sh
export d=`date +%Y%m%d%H%M%S`
mkdir -p /data/dbbak/baktables/$d
for i in `echo "show tables" | mysql -u bak -ppassword db|grep -v Tables`;
do
echo $i; mysqldump --add-drop-table --allow-keywords -q -a -c -u bak -ppasswod mbook_hd $i > backup/$d/$i.sql
done
tar czf backup/$d.tar.gz backup/$d/
rm -rf backup/$d/
lftp -e "cd /dbbak/; mput -c $d.tar.gz; quit" -u bak,password sftp://192.168.0.138
参考http://ocaoimh.ie/simple-mysql-backup/
10G级别的可以每天作一次备份,100G级别看带宽和硬盘,T级没有经验
#!/usr/bin/env python
import string, os, sys
dir = '/home/waterye/works/'
files = os.listdir(dir)
for f in files:
if not os.path.isfile(dir+os.sep+f): continue
linecount = 0
fp = open(dir+os.sep+f,'r')
for line in fp:
linecount += 1
fp = open(dir+os.sep+f,'r')
for i,line in enumerate(fp):
if (i==linecount-1 and line.endswith('\n')):
print f
print "--------------------------------"
* bash太难理解,还是用py看上去舒服,虽然不专业,但能完成任务就行