Detail Linux operation and maintenance CentOS system SVN double backup Shell script
- 2020-06-03 09:10:01
- OfStack
preface
SVN, short for Subversion, is an open source version control system that USES a branch management system. To put it simply, SVN is for the purpose of sharing resources with multiple people for the development of the same project.
As a code management tool, it is particularly important to backup operation, here take this backup strategy: in the implementation of local backup at the same time, let Shell script automatically upload data to the other one FTP backup server, the long-distance backup strategy cost is small, no storage, and high safety system, thought and double backup, local and long-distance data damage probability is much lower.
Backup Policy description
Using CentOS 6 series system, install vsftpd and modify configuration parameters. In addition, the backup directory of vsftpd can be RAID1 or RAID5.
The script executes a local directory backup of the svn project and then uploads the backup files to the FTP server to achieve a double backup.
Backup steps
Install and configure vsftpd
Use yum to install directly.
yum -y install vsftpd
Modify the configuration to allow the user to upload since the upload operation is to be performed. Anonymous user operations are not recommended for security reasons.
After modifying the configuration, the unnecessary ES37en. conf parameters are masked and displayed as:
[root@private ~]# grep -v "^#" /etc/vsftpd/vsftpd.conf | grep -v "^$"
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
chroot_local_user=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
The statement of chroot_local_user=YES needs to be highlighted 1. Its purpose is to restrict the user's login permission, that is, all local users can only log in vsftpd in their own home directory. This is based on security considerations, and this example script will also be based on this point.
Create the ftp login user
Create a backup user on the backup server, this time create user svn, and assign password to it, should also change their home directory to backup directory, local backup directory is: /data/backup/ svn-ES56en /, so that more convenient backup work, the following script and so on.
[root@private ~]# useradd -d /data/backup/svn-backup/ svn
[root@private ~]# echo "svnpasswd" | passwd --stdin svn
Changing password for user svn.
passwd: all authentication tokens updated successfully.
Configure the svn warehouse
First, check whether subversion is installed on the operating system. Generally, centos is installed by default. If not, use the following command to install quickly
rpm -qa subversion
yum -y install subversion
## Create a version library
svnadmin create /data/svn // The file directory here can be set up by itself
## configuration svnserve , the above version library `/data/svn ` Created under the folder will be generated conf Folder, enter `/data/svn/conf` There's going to be an underside 3 A file
[root@private svn]# ls conf/
authz passwd svnserve.conf
## Need to modify `svnserve.conf` Modify the following parts:
anon-access = read
auth-access = write
password-db = passwd
authz-db = authz
## Modify the `passwd` File as follows:
[users]
username = password // Here, username and password Your Settings
## The configuration file `authz` Finally add the following two lines ( These two rows are solved SVN Client side solution authorization failed The problem )
[/]
* = rw
## Start the svnserve You can:
svnserve -d -r /home/myrepos/
Backup script
This script sets the polling cycle to be once every 30 days, and Shell will automatically delete files that are 30 days old. Set up the corresponding backup user in vsftpd and the svn script contents are as follows:
#!/bin/bash
SVNDIR="/data"
SVNADMIN="/usr/bin/svnadmin"
DATE=$(date +%Y-%m-%d)
OLDDATE=$(date +%Y-%m-%d -d'30 days')
BACKDIR="/data/backup/svn-backup"
[ -d ${BACKDIR} ] || mkdir -p ${BACKDIR}
LogFile=${BACKDIR}/svnbak.log
[ -f ${LogFile} ] || touch ${LogFile}
mkdir ${BACKDIR}/${DATE}
for PROJECT in svn
do
cd $SVNDIR
$SVNADMIN hotcopy $PROJECT $BACKDIR/$DATE/$PROJECT --clean-logs
cd $BACKDIR/$DATE
tar zcvf ${PROJECT}_svn_${DATE}.tar.gz $PROJECT > /dev/null
rm -rf $PROJECT
sleep 2
done
HOST=localhost
FTP_USERNAME=svn
FTP_PASSWORD=Haiyuan
cd ${BACKDIR}/${DATE}
ftp -i -n -v <<!
open ${HOST}
user ${FTP_USERNAME} ${FTP_PASSWORD}
bin
cd ${OLDDATE}
mdelete *
cd ..
rmdir ${OLDDATE}
mkdir ${DATE}
cd ${DATE}
mput *
bye