LoginSignup
2
0

More than 5 years have passed since last update.

外付けHDD(NTFS)をオートマウントしてバックアップをとる

Posted at

CentOS7で、NTFS形式のHDDに、定期的に/data以下のバックアップをとりたい

yum install

yum -y install rsync autofs ntfs-3g

autofsの設定

/mnt/usbhdがマウントポイント
/dev/sdb1が外付けHDD

$ cat /etc/auto.master 
/mnt /etc/auto.home --timeout 60

$ cat /etc/auto.home 
usbhd     -fstype=ntfs-3g    :/dev/sdb1

/mnt/usbhdへのアクセスがあれば自動的に外付けHDDをntfs-3gを用いてマウントする
60秒間アクセスがなかった場合、自動でアンマウントする

シェルスクリプトの作成

backup.sh
ls /mnt/usbhd
rsync -auv --iconv=CP932,UTF-8 /data/* /mnt/usbhd/

lsコマンドでもcdコマンドでも、お好きなもので
今回文字コードの変換が必要だったため、iconvオプションを使っている
iconvオプションを使うと、更新されていないファイルも上書きしようとする
コピー元に*をつけると挙動が変わるそう
詳しくはわからないので、分かる方いらっしゃいましたらご教授ください

crontab設定

毎日0時0分にバックアップを取るように設定

$ crontab -e
0 0 * * * sh backup.sh
2
0
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
2
0