21
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

フォルダを圧縮して自動バックアップするスクリプト

Posted at

##シェルスクリプトを作成

vim images_backup.sh

#####images_backup.sh

#!/bin/sh

# バックアップファイルを何日分残しておくか
period='+7'
# バックアップファイルを保存するディレクトリ
dirpath='/path/to/backup/images'

#バックアップ元フォルダ
backupfolder="/path/to/from"

# ファイル名を定義(※ファイル名で日付がわかるようにしておきます)
mydate=`date +%y%m%d%H%M%S`
filename="images_$mydate.tar.gz"
#backup実行
tar -zcvf $dirpath/$filename $backupfolder

# パーミッション変更
chmod 700 $dirpath/$filename

# 古いバックアップファイルを削除
find $dirpath -type f -daystart -mtime $period -exec rm {} \;

##権限設定の変更

chmod 700 images_backup.sh
21
22
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
21
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?