マイン マイン
システム開発


A backup strategy for websites

A backup strategy for websites

This article is about an attempt to backup files and MySQL databases on a Linux host.

1. First, create a local git repos, called /git. Set permission: 700 unreadable, except the ower.

2. Each sites, use versioning:

In order to secure .git folder, the domain mount point in HTTP server must be like /srv/web-a/public (in a subfolder).Otherwise, we need deny access to .git from webserver.

3. Whenever you make changes, do a commit and push it to backup repos (keep it updated!). We can even schedule to git on daily using cron (done later). This keep uploads and data are all the lastest in repos!

4. Database will be stored in /git/db (althought it’s not a repos :D )
We need create an user for dumping, with minimal permission as needed:

5. Make a script at /home/you/backup.sh, chmod 700 (runable and readonly for you):

We can customize to dump each of your desire database.
The most important option is –lock-tables=false. It helps websites keep runing while dumping.
The second line is used to remove old backup aged more than 15 days.

6. Finally we need a cron to run:

This will run on everyday at 23:00. Enjoy you night without worry! : )

7. When we are in trouble, we can use powerful git to restore the version we want. Currently database dump is not optimized, because it’s a full backup. If there is a solution for incremental backup, it’s better to save space and able to archive longer timespan.

この記事を書いた人
マイン

ベトナム生まれの開発者、私はPHPとかCSS/JS/HTML/Linux server経験があります。ひまの時に日本語は勉強します。

札幌市中央区北3条西26丁目3-8 N2ビル3F 〒064-0823 TEL:011-640-5437 FAX:011-640-5434
東京都港区六本木4丁目2-35 アーバンスタイル六本木三河台2F 〒106-0032 TEL:03-5772-1414 FAX:03-5772-1404
NADIA BANGKOK / 240 soi 52 Romklao Road Ladkrabang Bangkok 10520 Thailand
NADIA HANOI / 5F, SIMCO Bld., 28 Pham Hung, Ha Noi, Viet Nam
PAGETOP
ナディアFacebookページ株式会社ナディア|Nations Media Design Nadia
PAGE TOP ↑