简单rsync备份脚本。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单rsync备份脚本。相关的知识,希望对你有一定的参考价值。

This script pulls in files with [rsync](http://samba.anu.edu.au/rsync/), storing them locally with hardlinks for unchanged, and real files for changed -files.

* KEY=$HOME/.ssh/id_dsa_passwdless -- an id_rtsa key without a password. --adding this to remote authorized keys must be done with care: you will prbably want to whitelist one IP-adress.
* RHOST=ssh.example.com -- the host where to connect to using ssh, or rsync.
* RUSER=example-username -- the username on the host. Must have _read_ access in the SOURCE dit (see below).
* LPATH=$HOME/Archive/example-com/ -- where to place the backups
* RPATH=/var/www/example-com/ -- the to-be-backuped dir.

You probably want to add this as script (`backup_example-com.sh`) in `~/bin`, or any other directory available in `$PATH`. And then add it to crontab.

See a howto here: http://troy.jdmz.net/rsync/index.html
  1. #!/bin/sh
  2.  
  3. RSYNC=/usr/bin/rsync
  4. SSH=/usr/bin/ssh
  5. KEY=$HOME/.ssh/id_dsa_passwdless
  6. RUSER=foo
  7. RHOST=ssh.example.com
  8. RPATH=/var/www/
  9. LPATH=$HOME/archive/example-com/
  10.  
  11. date=`date "+%Y-%m-%dT%H:%M:%S"`
  12.  
  13. $RSYNC -v -n -az -e "$SSH -i $KEY" --link-dest=$LPATH/current $RUSER@$RHOST:$RPATH $LPATH/back-$date
  14.  
  15. rm $LPATH/current &&
  16. ln -s $LPATH/back-$date $LPATH/current

以上是关于简单rsync备份脚本。的主要内容,如果未能解决你的问题,请参考以下文章

rsync如何同步单个文件到服务器上,使用rsync命令将备份同步到远程服务器的四个简单步骤...

Rsync+shell脚本完成自动化备份

rsync 目录备份脚本

执行rsync备份脚本出现的报错

rsync+shell 脚本完成自动化备份

sh 我的rsync备份脚本