云服务器资料(代码APP,SVN,数据库)备份资料都是需要同步至本地存储上,
lftp协议配合ftp,sftp,http等协议实现备份
脚本:
#!/bin/bash
BHOST=10.0.0.254
BUSER=guest
BPASS="guest"
local_Dir_backup_svn=/data/backup/svn/svn_lbd
local_Dir_backup_www=/data/backup/www/www_lbd
local_Dir_backup_rds=/data/backup/rds/rds_lbd
remote_Dir_backup_svn=/data/backup/svn_backup
remote_Dir_backup_www=/data/backup/www_backup
remote_Dir_backup_rds=/data/backup/rds_backup
log_file=/data/backup/get_back_local.log
Today=date '+%Y-%m-%d'
#####creat back dir
mkdir "$local_Dir_backup_svn"/"$Today"
mkdir "$local_Dir_backup_www"/"$Today"
mkdir "$local_Dir_backup_rds"/"$Today"
echo -e '\n'"###############" >>$log_file
echo start date
>>$log_file
#####delete old back
find $local_Dir_backup_svn -name "20" -type d -mtime +20|xargs rm -rf
find $local_Dir_backup_www -name "20" -type d -mtime +20|xargs rm -rf
find $local_Dir_backup_rds -name "20*" -type d -mtime +20|xargs rm -rf
sleep 2
#####get new back
lftp -u ${BUSER},${BPASS} sftp://${BHOST}:22 <<EOF
mirror "$remote_Dir_backup_svn"/"$Today" "$local_Dir_backup_svn"/"$Today"
mirror "$remote_Dir_backup_www"/"$Today" "$local_Dir_backup_www"/"$Today"
mirror "$remote_Dir_backup_rds"/"$Today" "$local_Dir_backup_rds"/"$Today"
bye
EOF
chmod 600 -R $local_Dir_backup_svn
chmod 600 -R $local_Dir_backup_www
chmod 600 -R $local_Dir_backup_rds
echo end date
>>$log_file
echo -e "###############"'\n' >>$log_file
put 上传文件
# put local_file -o remote_file
# lftp :~> ?
# !<shell-command> (commands)
# alias [<name> [<value>]] attach [PID]
# bookmark [SUBCMD] cache [SUBCMD]
# cat [-b] <files> cd <rdir>
# chmod [OPTS] mode file... close [-a]
# [re]cls [opts] [path/][pattern] debug [<level>|off] [-o <file>]
# du [options] <dirs> exit [<code>|bg]
# get [OPTS] <rfile> [-o <lfile>] glob [OPTS] <cmd> <args> help [<cmd>]
# history -w file|-r file|-c|-l [cnt] jobs [-v] [<job_no...>]
# kill all|<job_no> lcd <ldir>
# lftp [OPTS] <site> ln [-s] <file1> <file2> ls [<args>]
# mget [OPTS] <files> mirror [OPTS] [remote [local]]
# mkdir [-p] <dirs> module name [args] more <files>
# mput [OPTS] <files> mrm <files>
# mv <file1> <file2> [re]nlist [<args>]
# open [OPTS] <site> pget [OPTS] <rfile> [-o <lfile>]
# put [OPTS] <lfile> [-o <rfile>] pwd [-p]
# queue [OPTS] [<cmd>] quote <cmd>
# repeat [OPTS] [delay] [command] rm [-r] [-f] <files>
# rmdir [-f] <dirs> scache [<session_no>]
# set [OPT] [<var> [<val>]] site <site-cmd>
# source <file> torrent [-O <dir>] <file|URL>...
# user <user|URL> [<pass>] wait [<jobno>] zcat <files>
# zmore <files>
网友评论