The backup strategy for subversion repositories
(English version is under construction)
ãããä¸ã«è³æã¯ãã£ã¦ãå ·ä½çéç¨æ¹æ³ã«é¢ããè¨è¿°ãå°ãªãããã«æããã®ã§ãsubversionãªãã¸ããªã®ããã¯ã¢ããã¹ãã©ãã¸ã¼ãèãã¦ã¿ã¾ããã以ä¸ã®ãããªæ¹æ³ã§ãã
ææ¡
- subversion ãã¼ã«ç¾¤ã«ã¤ãã¦ã®ç¥èãããå ´åã¯ãsvnadmin dump 㨠hot-backup.py ãçµã¿åããã¦ä½¿ããåè ã¯ããã¯ã¹ã¯ãªããã¨ãã¦å©ç¨ããã³ãããæ¯ã®ãã³ããåå¾ãããå¾è ã¯é±æ¬¡ãã©ã¼ãªã³ã°ã«å©ç¨ããã
- ç°¡æãªæ¹æ³ã¨ãã¦ãrsync ã使ãæ¹æ³ãã·ã³ã°ã«ã¦ã¼ã¶ã§å©ç¨ãã¦ããããæ´æ°é »åº¦ãããã»ã©ã§ããªãã¬ãã¸ããªã§ããã°æå¹ã
- ã¾ã£ããããããªãå ´åã¯æåºãããªãã§ã製åãè²·ãã
è¨å®æ¹æ³
post-commit ããã¯ã¹ã¯ãªãããè¨è¿°ãã
ã¬ãã¸ããªçæç´å¾ã«ã¯ãhookãã£ã¬ã¯ããªã«ããã¤ãã®ãµã³ãã«ãç½®ããã¦ããã
tmishina-macmini:/data/svn tmishina$ svnadmin create sample tmishina-macmini:/data/svn tmishina$ ls sample/ total 16 -rw-r--r-- 1 tmishina admin 379 5 6 11:57 README.txt drwxr-xr-x 4 tmishina admin 136 5 6 11:57 conf drwxr-xr-x 2 tmishina admin 68 5 6 11:57 dav drwxr-sr-x 10 tmishina admin 340 5 6 11:57 db -r--r--r-- 1 tmishina admin 2 5 6 11:57 format drwxr-xr-x 11 tmishina admin 374 5 6 11:57 hooks drwxr-xr-x 4 tmishina admin 136 5 6 11:57 locks tmishina-macmini:/data/svn tmishina$ ls sample/hooks/ total 72 -rw-r--r-- 1 tmishina admin 2014 5 6 11:57 post-commit.tmpl -rw-r--r-- 1 tmishina admin 1615 5 6 11:57 post-lock.tmpl -rw-r--r-- 1 tmishina admin 2254 5 6 11:57 post-revprop-change.tmpl -rw-r--r-- 1 tmishina admin 1542 5 6 11:57 post-unlock.tmpl -rw-r--r-- 1 tmishina admin 2932 5 6 11:57 pre-commit.tmpl -rw-r--r-- 1 tmishina admin 2016 5 6 11:57 pre-lock.tmpl -rw-r--r-- 1 tmishina admin 2763 5 6 11:57 pre-revprop-change.tmpl -rw-r--r-- 1 tmishina admin 1987 5 6 11:57 pre-unlock.tmpl -rw-r--r-- 1 tmishina admin 2136 5 6 11:57 start-commit.tmpl
ã¾ã post-commit.tmpl ã post-commit ã«å称å¤æ´ããä¾ãã°ä»¥ä¸ã®ããã«è¨è¿°ããã
#!/bin/sh REPOS="$1" REV="$2" SVNADMIN=/sw/bin/svnadmin DUMPDIR=/data/backup/dump ZIP=/usr/bin/zip "$SVNADMIN" dump "$REPOS" -r "$REV" --incremental > "$DUMPDIR"/"$REV" $ZIP ${DUMPDIR}/${REV}.zip ${DUMPDIR}/${REV} rm ${DUMPDIR}/${REV}
ãã®ã³ã¼ãã§ã¯ãã³ããããããã°ããã®revisionããã³ããã¦zipã¢ã¼ã«ã¤ãã«ä¿åããï¼SVNADMIN, DUMPDIR, and ZIP ã¯å¯¾è±¡ç°å¢ã«åè´ããããå¤æ´ããï¼ãDUMPDIRã¯ã¬ãã¸ããªã¨ç©ççã«ç°ãªããã£ã¹ã¯ã«ããã¦ããã®ãããã
ç·¨éå¾ãpost-commitã®ãã¼ããã·ã§ã³ã755ï¼å®è¡å±æ§ä»ãï¼ã«å¤æ´ãã¦ããã
hot-backup.pyãè¨å®ãã
hot-backup.pyã¯subversionä»å±ã®ãããããã¯ã¢ãããã¼ã«ï¼ãããããã¯ã¢ããã§ã¯ããªãã¸ããªãå¤æ´ããã¦ããæä¸ã§ãããã¯ã¢ãããåããã¨ãã§ããï¼ãåæè¨å®ã§ã¯64åã®ãã¼ã¸ã§ã³ãä¿åãããã¨ã«ãªã£ã¦ããããå®éã«ã¯ææ°ã®ï¼åããããã°ããï¼ãã®ï¼åã¯ææ°ç¶æ ã®å®å ¨ãªãã©ã¼ã«ãªã£ã¦ããï¼ã®ã§ããããæ¸ãæãããhot-backup.py ãã以ä¸ã®è¨è¿°ãè¦ã¤ãã¦ã"64" ã "1" ã«å¤ããã
# Number of backups to keep around (0 for "keep them all") num_backups = 64
åæããã¯ã¢ãããä½æãã
ã³ããããçºçããåã«ãhot-backup.py ã使ã£ã¦åæããã¯ã¢ããï¼ãã©ã¼ï¼ãä½æãã¦ãããä¾ãã°/data/svn/sampleã¨ããã¬ãã¸ããªã/data/backup/以ä¸ã«ãã©ã¼ããå ´åã¯ã以ä¸ã®ããã«ã³ãã³ããå®è¡ããã
% hot-backup.py /data/svn/sample /data/backup
hot-backup.py 㯠/data/backup/sample-1 ã¨ãããã£ã¬ã¯ããªãçæãããä¸èº«ã¯ /data/svn/sample ã¨å ¨ãåãã«ãªã£ã¦ããã¯ããããã§ãï¼ãã¯ããã¯ã¢ããåå¾æç¹ã«ãããææ°ãªãã¸ã§ã³çªå·ãªã®ã§ãç°å¢ã«ãã£ã¦ã¯1ã§ã¯ãªããã¨ãããã
ã¹ã±ã¸ã¥ã¼ã«ã®ä½æ
hot-backup.py ã«ãããã©ã¼ãªã³ã°ãã¹ã±ã¸ã¥ã¼ã«ã«è¼ãããã¹ã±ã¸ã¥ã¼ã«ã§å®è¡ããä½æ¥ã¯ä»¥ä¸ã®äºã¤ã
- ãã©ã¼ä½æ
- ãã³ãåé¤
åè¿°ã®éãããã©ã¼ã¯å®å ¨ãªããã¯ã¢ããã«ãªã£ã¦ããã®ã§ããã®æç¹ã¾ã§ã®ãã³ããã¡ã¤ã«ã¯å¿ è¦ãªããªããããã«ãã³ããã¡ã¤ã«ã¯ãã®æç¹ã§åé¤ãã¦ããã
ã¹ã±ã¸ã¥ã¼ãªã³ã°ã®æ¹æ³ã¯OSã«ãã£ã¦ç°ãªããä¾ãã° OpenSUSE 10 ã§ããã°ã以ä¸ã®ãããªã¹ã¯ãªããã /etc/cron.daily/ ã«ã³ãã¼ãã¦ãå®è¡å±æ§ãã»ãããã¦ããã
#! /bin/sh REPOS=/data/svn/sample BACKUPDIR=/data/backup DUMPDIRNAME=dump HOTBACKUP=/sw/share/svn/tools/hot-backup.py ${HOTBACKUP} ${REPOS} ${BACKUPDIR} && rm ${BACKUPDIR}/${DUMP}/*.zip
References
- bluegate.org - このウェブサイトは販売用です! - bluegate リソースおよび情報
- subversionメーリングリスト中のスレッド
- WeekBuildのHACK日記 ディスククラッシュ å®éã«ã¯ã©ãã·ã¥ãã人ã®æ¥è¨