“A stitch in time saves nine”, goes an old saying. "時間のステッチ9 "と、ことわざにも保存されます。 In the world of computers we refer to that stitch as backups.我々のバックアップとしては、ステッチを参照してくださいコンピュータの世界では。 When running a production IT infrastructure, it is imperative that we achieve an uptime on our servers and applications of as close to a hundred percent as possible. ITインフラストラクチャが、それが不可欠であることできるだけ100パーセントに近いのアプリケーションをGoogleのサーバーとアップタイムを実現するには、生産を実行している。 While there are a number of ways to make an IT infrastructure solid, it is impossible to make it failure proof.一方で、 ITインフラストラクチャを固体にする方法はいくつもある、それを証明する失敗することは不可能です。 So we make a plan B.だから私たちには、プランBで
Servers are made of three broad layers - the hardware, the operating system and applications, and the data.サーバーの3つの幅広い層で作られています-ハードウェア、オペレーティングシステム、アプリケーション、およびデータ。 In case of a hardware failure it is rather simple to replace the machine with a new one.それではなく、新しいものには、マシンの代わりにハードウェア障害が発生した場合は単純だ。 Installing the operating system and applications too are relatively simple.は、オペレーティングシステムやアプリケーションのインストールも比較的簡単です。 The part that is hard to replace is the data and configuration that your applications use.その代わりに、データと設定のアプリケーションを使用しているハードされている部分。 In case of failure this is the part that can not be replaced.障害が発生した場合は、この問題を置き換えることができない部分です。 So we backup that data on a regular basis.だから、バックアップは定期的にデータ。 We back it up in such a way that it becomes easy to retrieve in case of emergency.私たちはこのような方法では、緊急の場合をバックアップを取得するために簡単になります。
I will guide you through writing a script to take daily backups on your system.私はあなたのシステムを毎日バックアップを取るためのスクリプトを書くことができます。 For this exercise I will use a server that runs the Apache web server, a MySQL database server, and has a directory on the /home partition that contains some data that needs to be backed up.私は、 Apache Webサーバ、 MySQLデータベースサーバーを実行するサーバーを使用し、そのニーズを背景には、一部のデータが含まれている / homeパーティション上のディレクトリがこの演習。 We will also backup the previous day’s Apache access logs in a separate backup directory.また、前日のApacheのアクセスログを個別にバックアップディレクトリにバックアップされます。 First, we need to create a directory where our backups will reside.まず、我々は我々のバックアップが存在するディレクトリを作成する必要があります。 As part of the exercise I have created a directory called BACKUP on the /opt partition.私はディレクトリは、 /パーティションを選択する前にバックアップと呼ばれる運動の一環として作成した。 We will organize the backups in this directory so that each days backup resides in a directory formed like this - /opt/BACKUP/YEAR/MONTH/DATE/ .は、それぞれの日のバックアップのディレクトリが以下のように形成さの中にある私たちはこのディレクトリにあるので、バックアップを整理する-が/ o pt/ バックアップ/年/月/日/ 。 So on the 11th of August 2008 the backups will go into /opt/BACKUP/2008/08/11/ .そのためには、 2008年8月の11日には、バックアップ/ opt/BACKUP/2008/08/11になるだろう/ 。 Let’s create these directories.これらのディレクトリを作成してみましょう。 Run the following set of commands as the root user.ルートユーザとしてのコマンドを実行して、 次のように設定します。
# mkdir -p /opt/backup/DATA/2008 # するmkdir - pの/ opt/backup/DATA/2008
# cd /opt/backup/DATA/2008 # のCD / opt/backup/DATA/2008
# mkdir 01 02 03 04 05 06 07 08 09 10 11 12 # するmkdir 01 02 03 04 05 06 07 08 09 10 11 12
# cd /opt/backup/DATA/ # CDのが/ opt /バックアップ/データ/
# cp -r 2008 2009に# cp - rを2008 2009
# cd /opt/backup/ # CDのが/ opt /バックアップ/
# cp -r DATA LOGに# cp - Rにデータをログ記録
See note below before issuing this last command.この最後のコマンドを発行する前に以下を参照してください注意してください。
# chown -R calvin.calvin /opt/backup # をchown - Rにcalvin.calvinが/ opt /バックアップ
We now have two sets of backup directories - one for data and another for log files.今のバックアップディレクトリの2つのセット-1つのデータを、別のログファイルがある。 With the backups directories created we are now ready to start writing the script. Note: I’m using the user calvin throughout this article.今では、スクリプトを書くのディレクトリのバックアップを開始する準備が生成される。 注 :私は、この資料では、ユーザーカルバンを使用している。 Please replace calvin with your own username.ご自身のユーザー名とカルバン交換してください。
########################################################### ################################################## #########
# CODE BEGINS HERE #のコードをここに始まる
########################################################### ################################################## #########
#!/bin/bash # ! / binに/ bashの
# SERVER DATA BACKUP V1.0 #サーバーのデータバックアップはv1.0
#########################
# BACKUP CONFIG #バックアップの設定
#########################
#Configure the month, date, and day #構成は、月、日付、日
YEAR=`date +”%Y”` # 2008年= `日付+ " % Y "に` # 2008
MONTH=`date +”%m”`# 11ヶ月= `日付+ " % m "と` # 11
DAY=`date +”%d”` # 14デイ= `日付+ " % d個の" ` # 14
YESTERDAY=`date –date=”yesterday” +%Y-%m-%d` # 2008-11-13 YESTERDAY = `日日= "昨日" + % Y字型%メートル- % d個の` # 2008年11月13日
YESTERDAY_DATE=`date –date=yesterday +%d` # 13 YESTERDAY_DATE = `日日=昨日+ % d個の` # 13
YESTERDAY_MONTH=`date –date=yesterday +%m` # 11 YESTERDAY_MONTH = `日日=昨日+ %メートル` # 11
YESTERDAY_YEAR=`date –date=yesterday +%Y` # 2008 YESTERDAY_YEAR = `日日=昨日+ %イ` # 2008
TODAY=`date +%Y-%m-%d` # 2008-11-14今日= `日付+ % Y字型%メートル- % d個の` # 2008年11月14日
TODAY_DATE=`date +%d` # 14 TODAY_DATE = `日付+ % d個の` # 14
# directories to backup toにバックアップする#ディレクトリ
DATA_BACKUP_PARENT_DIR=/opt/backup/DATA/ # <-- Change this your data backup dir DATA_BACKUP_PARENT_DIR =が/ opt /バックアップ/データ/ # < -変更は、データディレクトリのバックアップ
LOG_BACKUP_PARENT_DIR=/opt/backup/LOG/ # <-- Change this your log backup dir LOG_BACKUP_PARENT_DIR =が/ opt /バックアップ/ログ/ # < -これはあなたのログのバックアップディレクトリを変更する
# Apache Document Root Directory # Apacheのドキュメントルートディレクトリ
APACHE_DOCROOT=/var/www/html/ APACHE_DOCROOT =を/ var / www / htmlの/
# MySQL Database config # MySQLデータベースの設定
DB_IP="localhost" # <-- Change this to the IP of your database server DB_IP = " localhost "を< -あなたのデータベースサーバーのI Pに変更#
DB_USER="calvin" # <-- Change this to your database username DB_USER = "カルバン" < -あなたのデータベースのユーザー名に変更#
DB_PASS="calvin_password" # <-- Change this to your database password DB_PASS = " calvin_password " < -あなたのデータベースパスワードに変更#
DB_NAME="clientlist" # <-- Change this to your database name DB_NAME = " clientlist " < -あなたのデータベース名に変更#
# Apache Log Dir # Apacheのログディレクトリ
APACHE_LOG_DIR="/var/log/httpd/" # <-- Change this to the path data of your logs APACHE_LOG_DIR = "は/ var / log / httpdを/ " < -あなたのログのパスのデータに変更#
# Application Files' Dir #アプリケーションファイルのディレクトリ
APP_FILES="/home/calvin/application_files/" # <-- Change this to the path of the data directory APP_FILES = " /ホーム/カルバン/ application_files / " < -データディレクトリのパスに変更#
# Config Dir #設定ディレクトリ
CONFIG_DIR="/etc/" # <-- Change this to the path data directory CONFIG_DIR = "は/ etc / " < -データディレクトリのパスに変更#
# Mail report address #メールレポートアドレス
EMAIL_ID="you@youremailid.com" # <-- Change this to your e-mail ID EMAIL_ID = " you@youremailid.com " < -あなたのe -メールするためのI Dをこの変更#
########################################################### ################################################## #########
# DATA BACKUP #データをバックアップ
########################################################### ################################################## #########
# Create and go into backup directory #とバックアップを作成するディレクトリに移動
cd $DATA_BACKUP_PARENT_DIR/$YEAR/$MONTH $ DATA_BACKUP_PARENT_DIR / $はYEAR / $ヶ月のCD
mkdir $DAYするmkdir $デイ
cd $DAY CDの$デイ
# Database backup #データベースのバックアップ
mysqldump -h ${DB_IP} -u ${DB_USER} -p${DB_PASS} ${DB_NAME} > ${DB_NAME}.db mysqldumpを- ( DB_USER ) 、 ( DB_PASS ) $ ( DB_NAME ) > $ $ p ( DB_NAME ) 。デシベル$ ( DB_IP ) - uを$時間
tar -zcvf ${DB_NAME}.tar.gz ${DB_NAME}.dbタール- zcvf $ ( DB_NAME ) 。 tar.gz $ ( DB_NAME ) 。デシベル
rm -f ${DB_NAME}.dbてrm - fを$ ( DB_NAME ) 。デシベル
# /etc backup #は/ etcのバックアップ
tar -zcf etc.tar.gz /etcタール- zcf etc.tar.gzは/ etc
# Application backup #アプリケーションのバックアップ
tar -zcf Apache_Doc_Root.tar.gz ${APACHE_DOCROOT}タール- zcf Apache_Doc_Root.tar.gz $ ( APACHE_DOCROOT )
tar -zcf App_Files.tar.gz ${APP_FILES}タール- zcf App_Files.tar.gz $ ( APP_FILES )
########################################################### ################################################## #########
# LOG BACKUP #ログのバックアップ
########################################################### ################################################## #########
# Create and go into backup directory
cd $LOG_BACKUP_PARENT_DIR/$YESTERDAY_YEAR/$YESTERDAY_MONTH $ LOG_BACKUP_PARENT_DIR / $ YESTERDAY_YEAR / $ YESTERDAY_MONTHのCD
mkdir $YESTERDAY_DATEするmkdir $ YESTERDAY_DATE
cd $YESTERDAY_DATE $ YESTERDAY_DATEのCD
# HTTPD Log Backup # httpdのログのバックアップ
for i in ${APACHE_LOG_DIR}/access_log.${YESTERDAY}*; do cp $i .; done私は$ ( APACHE_LOG_DIR ) / access_logで$ ( YESTERDAY ) * ;行う$ cpは私。 ;行わ
for i in access_log.${YESTERDAY}*; do gzip $i; done access_logでのi $ ( YESTERDAY ) * ;私をgzip $行う;行わ
########################################################### ################################################## #########
# Send out mail notificationsメールの通知を送信する#
########################################################### ################################################## #########
# Mail notify #メール通知
du -shc $DATA_BACKUP_PARENT_DIR/$YEAR/$MONTH/$DAY/* | mail -s “Backup for ${HOSTNAME}::DATA done :)” ${EMAIL_ID}デュ- shc $ DATA_BACKUP_PARENT_DIR / $はYEAR / $月/ $日/ * |メールが" $ (ホスト名)のバックアップ: :データ行わ: ) " $ ( EMAIL_ID )
du -shc $LOG_BACKUP_PARENT_DIR/$YESTERDAY_YEAR/$YESTERDAY_MONTH/$YESTERDAY_DATE/* | mail -s “Backup for ${HOSTNAME}::LOG done :)” ${EMAIL_ID}デュ- shc $ LOG_BACKUP_PARENT_DIR / $ YESTERDAY_YEAR / $ YESTERDAY_MONTH / $ YESTERDAY_DATE / * |メールが" $ (ホスト名)のバックアップ: :行わログ: ) " $ ( EMAIL_ID )
########################################################### ################################################## #########
# CODE ENDS HERE #のコードをここに終わる
########################################################### ################################################## #########
Save this script in a directory such as /home/calvin/scripts/backup.sh.あるディレクトリには/ home /カルバン/スクリプト/ backup.shなど、このスクリプトを保存します。 Give executable permissions to the file:実行可能ファイルへのアクセス許可を与える:
# chmod +x /home/calvin/scripts/backup.sh # chmod + xは/ homeを/カルバン/スクリプト/ backup.sh
Now you are good to go.これで行ってもいいです。 Run the script form your command line:スクリプトを実行してコマンドライン形式:
# /home/calvin/scripts/backup.sh # /ホーム/カルバン/スクリプト/ backup.sh
You can also optionally add this script as a cron job so that it will be executed on a daily basis at a time of your choice.また、オプションており、これは日常的にお好みの時間に実行されるスクリプトはcronジョブとして追加することができます。 If you want to run this script at 4 AM daily do the following:もし4ではこのスクリプトを実行したい場合は、次の操作を行う毎日午前:
# crontab -e # crontabをメールする
Create a new line in the file that opens and add the following:を開き、次の追加は、ファイル内の新しい行を作成します:
0 4 * * * /home/calvin/scripts/backup.sh > /dev/null 0 4 * * * /ホーム/カルバン/スクリプト/ backup.sh >は/ dev / nullを
There you go.そうそう。 Your server will now backup your data, database, configuration files, application files, and log files to /opt/backup everyday at 4 AM.現在使用してデータをサーバー、データベース、構成ファイル、アプリケーションファイル、バックアップするとログファイルが/ opt / 4時すぎ 、日常のバックアップ。 A smart thing to do now would be to export these backups to a remote machine so that you don’t lose your backups if your server faces problems.を行うためのスマートなことは現在、リモートマシンへのサーバーの問題に直面している場合は、お客様のバックアップを失わないようにするこれらのバックアップをエクスポートすることです。 We will cover how to do that in my next article.私たちはどのようにカバーするかが私の次の資料に記載されている。






















{ 0 comments… ( 0コメント... add one now今すぐ追加 } )
Leave a Commentコメントを残しなさい