[Linux] PHP programmers play with Linux series-automatic backup and SVN, linuxsvn
1. PHP programmers turn to the Linux series-how to install and use CentOS
2. PHP programmers play with Linux series-lnmp Environment Construction
3. PHP programmers play with the Linux series-build an FTP code Development Environment
4. PHP programmers turn to the Linux series-back up and restore MySQL
My code is often being developed and modified. For the sake of code security, for example, when a file is deleted by mistake or when an error is corrected, it can be recovered. I want to back up the code. backup code. The simplest task is to use the linux timing mechanism and shell commands to package files, save the files by date every day, and save the backups for the last seven days.
Prepared commands
Date command, print the current system time, add a parameter + % F, print the formatted full date, date + % F. Command replacement character '', get the return value of the command in it.
Use the variable $ {variable name} in the string, such as echo "hi $ {name }"
Package command tar-czf package name *, c is create, z is gzip compression, f is file format, for example: tar-czf 1.tar.gz * pack all files in the current directory to 1.tar.gz
Decompress the command tar-xf package name, and x is the extract extraction, for example, tar-xf 1.tar.gz.
Find/-mtime + 10-exec rm {}\; mtime is the modified time modification time, measured in days, + 10 is 10 days ago;-exec is the execution command, -exec command {}\; braces will be replaced by the current search results, \ is a fixed escape. for example: find/root-mtime + 10-exec wc-l {}\; count the number of lines of the file 10 days ago
Final script
#! /Bin/base # define the backup file path backupFilePath = "/root/web"; # define the backup file name currentDate = 'date + % F'; backupFileName = "web_backup_1_1_currentdate1_.tar.gz "; # define the directory sourceFileDir = "/var/www/html/" to be backed up /"; # define the backup file storage directory destinationDir = "/root/web/" # package backup cd $ sourceFileDir; tar-czf $ backupFileName *; mv $ backupFileName $ destinationDir; # delete the file "find $ destinationDir-mtime + 10-exec rm {}\" 10 days ago {}\;
Enable timing
Edit the/etc/crontab file
*/1 ***** root sh/root/shell/backup. sh
Minutes, hours, days, months, and weeks.
Set up SVN Server
Now the code can be packaged and saved in a timely manner, all of which are backed up by one piece. Now I want to build an SVN server and keep the code according to the modified version to make it more intelligent.
Install svn by using the command: yum install subversion.
After the installation is complete, you need to create a code repository. Use this command svnadmin create svnrepos/to create a svnrepos directory in the current directory. This is the repository directory.
Configure SVN
After the repository is created, the user who configures svn now enters the svnrepos/conf/directory. There are three configuration files: authz, passwd, and svnserve. conf.
1. Configure svnserve. conf
Authz-db = authz
Password-db = passwd
Literally, you should enable verification to use these two files.
2. Configure authz
A group of users that can read and write
[Groups]
Svn_users = shihan1, shihan2
[/]
@ Svn_users = rw
3. Configure passwd
Configure the password.
[Users]
Shihan1 = aaabbbccc
Shihan2 = aaabbb
Enable SVN Service
Run the svnserve-d-r svnrepos/-d command as the background service.-r is the directory used.