LoginSignup
9
8

More than 5 years have passed since last update.

実践的なrsyncを使ったbackup

Last updated at Posted at 2015-11-24

rsyncで毎日あるフォルダをバックアップしたい。
そんなあなたに。

要約

毎日rsyncしてzipでアーカイブする。
フォルダ階層はこんな感じ。

backup/
|-- 20151120.zip
|-- 20151121.zip
|-- 20151122.zip
`-- 20151123.zip

方法

以下、バックアップスクリプト。
/path/toな箇所を書き換える。
src_dir: バックアップ元。ssh先のバックアップOK。(例: hoge.com:/path/to/dir )
dest_dir: バックアップ先

#/bin/sh

src_dir="/path/to/dir"
dest_dir="/path/to/dir"

backup_dir=`date +'%Y%m%d'`

mkdir -p ${dest_dir}/${backup_dir}
rsync -a ${src_dir} ${dest_dir}/${backup_dir}

# zip archive
cd ${dest_dir} && zip -rm ${backup_dir}.zip ${backup_dir}

定期実行

毎日実行するなら /etc/crontab にでも書いておこう。

# everyday backup at 22:10
10 22 * * * root /path/to/basic_backup.sh >> /path/to/backup.log

参照

gistも置いておいたから自由に使ってね!
https://gist.github.com/Yuji-Kuroko/e585859307f7477c6447

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8