Skip to content

Instantly share code, notes, and snippets.

@brokendish
Created August 11, 2012 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brokendish/3324087 to your computer and use it in GitHub Desktop.
Save brokendish/3324087 to your computer and use it in GitHub Desktop.
月次バックアップ--世代管理:3世代「シェル本体」
#!/bin/bash
#------------------------------------------------
#実行月を取得
prefix=`date +\%m`
#------------------------------------------------
#バックアップ保存先
ToBkPath="/Ubuntu-backup/backup/monthly"
#バックアップ名
ToBkName="Ubuntu_BKUP"
#バックアップ対象
FromBk="/home /etc"
#バックアップ対象外
UnBk1="/home/hoge/.gvfs"
#------------------------------------------------
#バックアップ取得
tar czplf ${ToBkPath}/${prefix}_${ToBkName}.tar.gz --exclude ${UnBk1} ${FromBk}
#バックアップが3世代あった場合は古いものを削除
tgt=`ls -1 ${ToBkPath}/[0-1][0-9]_${ToBkName}.tar.gz|wc -l`
if [ $tgt -gt 3 ];
then
#過去分バックアップ削除
ls -1tr ${ToBkPath}/[0-1][0-9]_${ToBkName}.tar.gz|head -1|xargs rm
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment