Scripts for SVN backup and recovery, remote backup based on rsync, and logging

Source: Internet
Author: User
Tags rsync

SVN server: 192.168.40.110

Backup server: 192.168.40.162

Local backup on SVN server

1. Full-scale backup

# vim  /data/shell/backup_svn.sh#!/bin/sh#path= $PATH:/usr/local/subversion/binexport path# Define time variables for file name suffix date=$ (date +%f)    #定义SVN库目录变量SVN_DIR_docs =/data/repositories/docs                svn_dir_tools=/data/repositories /tools  #定义备份文件存放目录变量SVN_BAK_DIR =/data/bak/  #初始化版本号, the full library backup must start from the 0 version number echo  ' 0 '  > /data/ svnnum/docs_svn_idecho  ' 0 '  > /data/svnnum/tools_svn_id   #取初始化版本号NUM_docs1 =$ (cat  /data/svnnum/docs_svn_id) num_tools1=$ (cat /data/svnnum/tools_svn_id)   #取当前最新的版本号NUM_docs2 =$ ( svnlook youngest  $SVN _dir_docs) num_tools2=$ (svnlook youngest  $SVN _dir_tools)  # Backup user authentication and authorization file  \cp  /data/Repositories/{authz,passwd} /data/bak/.  #开始备份 # To determine if the backup was successful and, if successful, The current latest version number is recorded in the temporary file for the next incremental backup using ALL_BACKUP_SVN () { svnadmin dump  $SVN _dir_docs  -r $ NUM_DOCS1: $NUM _docs2  --incremental >   $SVN _bak_dir/docs_bak_$dateif [ $? -eq 0 ]; thenecho  $NUM _docs2 > /data/svnnum/docs_svn_idelseecho  "$ (date +%f)  docs  backup fail  >> /tmp/svnback.logfisvnadmin dump  $SVN _dir_tools   -r  $NUM _tools1: $NUM _tools2  --incremental >   $SVN _bak_dir/tools_bak_$ dateif [ $? -eq 0 ];thenecho  $NUM _tools2 > /data/svnnum/tools_svn_ idelseecho  "$ (date +%f)  tools backup fail ..."  >> /tmp/svnback.logfi}  all_backup_svn

2. Incremental backup

# vim  /data/shell/day_backup_svn.sh#!/bin/bash#path= $PATH:/usr/local/subversion/binexport  path# defining time variables for file name suffixes date=$ (date +%f)    #定义SVN库目录变量SVN_DIR_docs =/data/repositories/docs               svn_dir_tools=/data/ repositories/tools  #定义备份文件存放目录变量SVN_BAK_DIR =/data/bak/  #取初始化版本号NUM_docs1 =$ (cat /data/svnnum/ docs_svn_id) num_tools1=$ (cat /data/svnnum/tools_svn_id)   #取当前最新的版本号NUM_docs2 =$ (svnlook youngest   $SVN _dir_docs) num_tools2=$ (svnlook youngest  $SVN _dir_tools)   #开始备份 # To determine if the backup was successful, The current latest version number is recorded in the temporary file for the next incremental backup using DAY_BACKUP_SVN () {if [  $NUM _docs1 -lt  $NUM _docs2 ];then  svnadmin dump  $SVN _dir_docs  -r  $NUM _docs1: $NUM _docs2  --incremental  >   $SVN _bak_dir/docs_bak_$dateif [ $? -eq 0 ];thenecho  $NUM _ docs2 > /data/svnnum/docs_svn_idelseecho  "$ (date +%f)  docs backup fail ..."  >> /tmp/svnback.logfifiif  [  $NUM _tools1 -lt  $NUM _tools2 ];thensvnadmin dump  $SVN _dir_tools   -r  $NUM _tools1: $NUM _tools2  --incremental >   $SVN _bak_dir/tools_bak_$ dateif [ $? -eq 0 ];thenecho  $NUM _tools2 > /data/svnnum/tools_svn_ idelseecho  "$ (date +%f)  tools backup fail ..."  >> /tmp/ Svnback.logfifi}day_backup_svn


3. Add a Scheduled task

# crontab-e#start0 2 * * */usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1# make a full backup every Sunday * * 0/data/she ll/backup_svn.sh &>/dev/null# Incremental Backup of SVN * * 1-6/data/shell/day_backup_svn.sh



4. Configure the Rsync server:

# rpm -qa rsync (If you install   yum install   rsync - Y) rsync-3.0.6-12.el6.x86_64# yum install xinetd -y Enable rsync# vim /etc/xinetd.d/ rsync # default: off# description: the rsync server is a  good addition to an ftp server, as it #        allows crc checksumming etc.service rsync{         disable = no        flags            = IPv6         Socket_type     = stream        wait             = no         user            = root         server          = /usr/bin/rsync         server_args     = --daemon         log_on_failure  += userid}

Rsync configuration file Available # vim  /etc/rsyncd.conf#rsync --daemon  --config=/etc/rsyncd.conf# Global options  strict modes =yes #  whether to check permissions for password files  port = 873#  default port 873 log  file = /var/log/rsyncd.log#  Log Record file  pid file = /var/run/rsyncd.pid#   Where the ID of the running process is written  [svn]path = /data/bak#  here is the name of the authentication module, which needs to be specified on the client side  max connections  = 0#  client Maximum number of connections, default 0 (No limit)  uid = root#  Specifies the uid gid = that the daemon should have when the module transfers files  root#  specifies that the gid ignore errors#  that the daemon should have when the module transmits the file can ignore some unrelated IO errors  read only =  yes# no client can upload files, yes read-only  write only = no# no client can download files, yes cannot download  hosts  allow = * #  any host connection   #hosts  deny = 10.5.3.1#  Disable the specified host connection  auth  users = root#  authenticated user name, if not this line, indicates that it is anonymous  secrets file = /etc/backserver.pas #  specifying the authentication password file location


5. Provide the authentication file, and the permission must be 600

# Vim/etc/backserver.pas root:123456# chmod 600/etc/backserver.pas


6. Restart the service

#/etc/init.d/xinetd Restart


7. Synchronizing backups to 192.168.40.162


Provide the authentication file, and the permissions must be 600

# Vim/etc/backserver.pas 123456# chmod 600/etc/backserver.pas# mkdir-p/data/bak/svn# vim/home/bak/backup_svn.sh #!/b in/bash# Backup SVN warehouse/usr/bin/rsync-vzrtopg--progress--delete [email protected]::svn/data/bak/svn--password-file=/etc/  Backserver.pas Add Timer Task # crontab-e#start0 2 * * */usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1# Backup svn35 01 * * */home/backup_svn.sh &>/dev/null#end


8. SVN Recovery test

# mkdir Docs # svnadmin Create Newrepos # svnadmin load Newrepos < docs_bak_mon# svnadmin load Newrepos < docs_bak_t UE # Svnadmin Load Newrepos < docs_bak_wed# svnadmin load Newrepos < docs_bak_thu# svnadmin load Newrepos < Docs_ bak_fri# svnadmin load Newrepos < Docs_bak_sun


This article is from the Linux tours blog, so be sure to keep this source http://openlinuxfly.blog.51cto.com/7120723/1671309

Scripts for SVN backup and recovery, remote backup based on rsync, and logging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.