linux – rsync / rsnapshot

前端之家收集整理的这篇文章主要介绍了linux – rsync / rsnapshot前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用rsnapshot,我的配置如下:
config_version  1.2
snapshot_root   /home/user/.snapshots/
cmd_cp  /bin/cp
cmd_rm  /bin/rm
cmd_rsync       /usr/bin/rsync
cmd_ssh /usr/bin/ssh
cmd_logger      /usr/bin/logger
cmd_du  /usr/bin/du
cmd_rsnapshot_diff      /usr/bin/rsnapshot-diff
interval        hourly  24
interval        daily   7
interval        weekly  4
verbose 2
loglevel        3
logfile /home/user/rsnapshot.log
lockfile        /home/user/rsnapshot.pid
backup  root@website.com:/home/user/ website/
backup_script   root@website.com:/home/user/backup_MysqL.sh website/MysqL/

我的sql备份文件:(故意留下东西)

### Setup dump directory ###
BAKRSNROOT=/.snapshots/tmp

#####################################
### ----[ No Editing below ]------###
#####################################
### Default time format ###
TIME_FORMAT='%H_%M_%S%P'

### Make a backup ###
backup_MysqL_rsnapshot(){
        local DBS="$($MysqL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
        local db="";
        [ ! -d $BAKRSNROOT ] && ${MKDIR} -p $BAKRSNROOT
        ${RM} -f $BAKRSNROOT/* >/dev/null 2>&1
#       [ $VERBOSE -eq 1 ] && echo "*** Dumping MysqL Database ***"
#       [ $VERBOSE -eq 1 ] && echo -n "Database> "
        for db in $DBS
        do
                local tTime=$(date +"${TIME_FORMAT}")
                local FILE="${BAKRSNROOT}/${db}.${tTime}.gz"
#               [ $VERBOSE -eq 1 ] && echo -n "$db.."
                ${MysqLDUMP} --single-transaction -u ${MUSER} -h ${MHOST} -p${MPASS} $db | ${GZIP} -9 > $FILE
        done
#               [ $VERBOSE -eq 1 ] && echo ""
#               [ $VERBOSE -eq 1 ] && echo "*** Backup done [ files wrote to $BAKRSNROOT] ***"
}

### Die on demand with message ###
die(){
        echo "$@"
        exit 999
}

### Make sure bins exists.. else die
verify_bins(){
        [ ! -x $GZIP ] && die "File $GZIP does not exists. Make sure correct path is set in $0."
        [ ! -x $MysqL ] && die "File $MysqL does not exists. Make sure correct path is set in $0."
        [ ! -x $MysqLDUMP ] && die "File $MysqLDUMP does not exists. Make sure correct path is set in $0."
        [ ! -x $RM ] && die "File $RM does not exists. Make sure correct path is set in $0."
        [ ! -x $MKDIR ] && die "File $MKDIR does not exists. Make sure correct path is set in $0."
        [ ! -x $MysqLADMIN ] && die "File $MysqLADMIN does not exists. Make sure correct path is set in $0."
        [ ! -x $GREP ] && die "File $GREP does not exists. Make sure correct path is set in $0."
}

### Make sure we can connect to server ... else die
verify_MysqL_connection(){
        $MysqLADMIN  -u $MUSER -h $MHOST -p$MPASS ping | $GREP 'alive'>/dev/null
        [ $? -eq 0 ] || die "Error: Cannot connect to MysqL Server. Make sure username and password are set correctly in $0"
}

### main ####
verify_bins
verify_MysqL_connection
backup_MysqL_rsnapshot

如何远程执行该.sh文件获取数据库并将其拉回?

编辑:
错误

rsnapshot hourly
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot hourly
----------------------------------------------------------------------------
ERROR: /usr/local/etc/rsnapshot.conf on line 18:
ERROR: backup_script \
         root@website.com:/home/user/backup_MysqL.sh" \
     is not executable or can't be found. Please use an absolute \
     path.
ERROR: ---------------------------------------------------------------------
ERROR: Errors were found in /usr/local/etc/rsnapshot.conf,ERROR: rsnapshot can not continue. If you think an entry looks right,make
ERROR: sure you don't have spaces where only tabs should be.

文件是chmod 777所以它没有被隐藏

我试过这样的事情,但我没有得到任何复制/拉过来.

backup_script  /usr/bin/ssh root@example.com 'MysqLdump -u root --all-databases | gzip --rsyncable > ~/all.sql.gz'    unused2

尝试:

backup_script /usr/bin/ssh user@website.com "/home/user/backup.script"  whatever/

它工作但无法复制文件.

编辑:

backup_script   /usr/bin/ssh root@remote.com "/home/user/backup_MysqL.sh"   blank/
backup_script   /usr/bin/scp -r root@remote.com:/.rsnapshots/tmp/ /.rsnapshots/tmp/       user/MysqL/

得到:

usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot hourly
----------------------------------------------------------------------------
ERROR: backup_script /usr/bin/scp -r root@remote.com:/.rsnapshots/tmp/ returned 1
WARNING: Rolling back "user/MysqL/"

解决方法

首先,您应该将备份脚本移动到远程系统.请记住,此处的文件正在远程系统上执行,而不是在本地文件(运行rsnapshot的文件)上执行.然后,一旦在远程系统上执行程序,您应该将文件移回本地系统.

像这样的东西应该工作:

backup_script /usr/bin/ssh user@website.com "/home/user/backup.script"  whatever/
backup_script /usr/bin/scp -r user@website.com:/home/user/your_data/ /.your_snapshot_root/rsnapshots/tmp/ target_dir_to_store_backups/

猜你在找的Linux相关文章