rsyncを介したバックアップスクリプト

何とかバックアップする必要がありました。 さらに、プロセッサがロードされず、場所が占有されず、バックアップがローテーションされて便利に配信されるようにします。 以前は常にfsbackupを使用していましたが、アーカイブを拒否したかったのです。 この問題を解決するために、ファイルシステムのハードリンク (いわゆるハードリンク)のrsyncとメカニズムが使用されました。



アーキテクチャ:大きなネジ付きの自立型サーバーがあります-スクリプトはそれで動作します。 sshアクセスを持つさまざまなサーバーがあり、ユーザーの公開キーが〜/ .ssh / authorized_keysに追加され、その下でバックアップスクリプトが機能します。



作業ロジック:ある時点で、sshスクリプトはリモートサーバー上のフォルダーのコンテンツをdomain.com/latestフォルダーと同期し、それを今日の日付のフォルダーにコピーし、ファイルへのハードリンクを作成し、作成日が7より古いフォルダーを削除します日。 なぜなら ディレクトリの内容のみが同期されるため、rsyncがファイルを取得する前に、クライアントマシンのクラウンでデータベースをダンプする必要があります。



長所:

-差分バックアップより少ないスペースを使用し、増分より多くのスペースを使用しない

-プロセッサの負荷が少ない アーカイバを使用しません(ネットワーク経由で送信する場合、その場で圧縮できます)

-かなり詳細なログ形式、エラーに関する電子メールアラートがある

-ハッキングやクライアントマシンの完全な破壊に対する耐性-攻撃者がバックアップを傷つけない



質問:

-なぜなら このスクリプトはもともと抄録で公開されていたため、このアプローチの有効性に関する権威ある意見を聞くことはできませんでした。考えを共有していただければ幸いです...



#!/bin/sh # simple rsync backup script written by farmal.in 2011-01-21 # # latest backup is always in $SDIR/domains/$domain/latest folder # all backups which are older than 7 days would be deleted # backup.ini file can't contain comments, empty lines and spaces in domain names # # example of a GOOD backup.ini: # mydomain.com user@mydomain.com:/path/to/public_html # SDIR="/usr/local/backup" SKEY="$SDIR/.ssh/id_rsa" SLOG="$SDIR/backup.log" PID_FILE="$SDIR/backup.pid" ADMIN_EMAIL="email@domain.com" if [ -e $PID_FILE ]; then echo "this task is already running or previous run was completed with errors on `hostname`" | mail -s "Some mess with backups on `hostname`..." $ADMIN_EMAIL exit fi touch $PID_FILE # redirecting all output to logfile exec >> $SLOG 2>&1 # parsing backup.ini file into $domain and $from variables cat backup.ini | while read domain from ; do destination="$SDIR/domains/$domain" # downloading a fresh copy in 'latest' directory echo -e "`date` *** $domain backup started">>$SLOG # start counting rsync worktime start=$(date +%s) rsync --archive --one-file-system --delete -e "ssh -i $SKEY" "$from" "$destination/latest" || (echo -e "Error when rsyncing $domain. \n\n For more information see $SLOG:\n\n `tail $SLOG`" | mail -s "rsync error" $ADMIN_EMAIL & continue) finish=$(date +%s) echo -e "`date` *** RSYNC worked for $((finish - start)) seconds">>$SLOG # cloning the fresh copy by hardlinking cp --archive --link "$destination/latest" "$destination/`date +%F`" # deleting all previous copies which are older than 7 days by creation date, but not 'latest' find "$destination" -maxdepth 1 -ctime +7 -type d -path "$destination/????-??-??" -exec rm -r -f {} \; echo "`date` *** The size of $domain/latest is now `du -sh $destination/latest | awk '{print $1}'` ">>$SLOG echo -e "`date` *** $domain backup ended">>$SLOG echo -e "`date` *** Total allocated `du -sh $destination | awk '{print $1}'`">>$SLOG echo -e "------------------------------------------------------------------">>$SLOG done rm $PID_FILE
      
      






All Articles