Linux git code warehouse && public warehouse && software warehouse daily automatic backup __linux

Source: Internet
Author: User
Tags rsync git clone

Linux version number: 14.04.1-ubuntu x86_64

Backup server address is: 172.29.71.59, backup root path is/home/backup

1.git Code warehouse automatic daily backup:

Server address: 172.29.71.111,git specified directory: 00.apps, Backup path is:/home/backup/codeserver_111

Step One:

cd/home/backup/codeserver_111
git clone--mirror Git@172.29.71.111:00.apps
git clone--mirror copies a git library that contains the latest remote branch as well as a history submission record.

Step Two:

Cd/etc
Vim crontab

Modify the Crontab file to add a daily backup timed task

#/etc/crontab:system-wide Crontab
# Unlike any other crontab you don ' t have to run the ' crontab '
# command to In Stall the new version when you edit this file
# and files in/etc/cron.d. These files are also have username fields, # that none of the other
crontabs do.

Shell=/bin/sh
path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m H Dom Mon Dow user	Command * * * *	root    cd/&& run-parts--report/etc/cron.hourly
6	*	* * r Oot	test-x/usr/sbin/anacron | | (CD/&& run-parts--report/etc/cron.daily)
6	* * 7	root	test-x/usr/sbin/anacron | | (CD/&& run-parts--report/etc/cron.weekly)
6	1 * *	root	test-x/usr/sbin/anacron | | (CD/&& run-parts--report/etc/cron.monthly)
#CodeServer_111
0 0 * * * *   root    git--git-dir=/home/backup/codeserver_111/00.apps.git remote Update

Step Three:

After you modify the crontab file, run the following command to take effect:

Service Cron Restart

Synchronize the latest 00.apps (Git library) on the 172.29.71.111 server to the backup server daily 00:00.

2. Daily automatic backup of public warehouses:

Server address: 172.29.71.57, backup path is:/home/backup/publicserver_57

Step One:

cd/home/backup/publicserver_57
Vim backup_public.sh
Create a new backup_public.sh script for daily automatic backups of public warehouses. The specific code is as follows:

#!/bin/bash

function Backup ()
{
        publichome=172.29.71.57
	
	# rsync && add password
	/usr/ Bin/expect <<-eof
	Set timeout
	spawn rsync--delete-r public@ $publichome:/home/public.

	Expect "public@ $publichome ' s password:"
	send "public\r"

	send "exit\r"
	expect EOF
	EOF        
}
Backup

rsync: Sync command--delete-r: If the source does not have this file, then the destination can not have, Force synchronous deletion (-r:recursive, recursive, for synchronizing folders).

Synchronizes the contents of the folder under the/home/public directory on the public warehouse server 172.29.71.57 to the backup server.

Step Two:

Cd/etc
Vim crontab
Modify the crontab file to continue adding daily backup timed tasks at the end of the file
#PublicServer_57
1 * * *   root   cd/home/backup/publicserver_57 &&/home/backup/ publicserver_57/backup_public.sh

Step Three:

After you modify the crontab file, run the following command to take effect:

Service Cron Restart

Synchronize the contents of the folder on the/home/public directory on the 172.29.71.57 server to the backup server daily 1:30.

3. Software warehouse automatic daily backup:

Server address: 172.29.71.47, backup path is:/home/backup/softserver_47

Step One:

Cd/home/backup/softserver_47
Vim backup_softserver.sh

Create a new backup_softserver.sh script for automatic daily backup of the software warehouse. The specific code is as follows:

#!/bin/bash
function Backup ()
{
softhome=172.29.71.47
        # rsync && add password
        /usr/bin/ Expect <<-eof
        set timeout
        spawn rsync--delete-r soft@ $softhome:/home/iptv/release/ci_release/dsv1 .
        Expect {
            "(yes/no)?" {
                   send "yes\r"
                   expect "soft@ $softhome ' s password:"
                   send "soft\r"
            }
            "soft@ $softhome ' s Password: "{
                   send" soft\r}
        send "exit\r"
        expect EOF
        EOF
}
Backup

rsync: Sync command--delete-r: If the source does not have this file, then the destination can not have, Force synchronous deletion (-r:recursive, recursive, for synchronizing folders).

Synchronizes the contents of the folder under the/home/iptv/release/ci_release/dsv1 directory on the Software warehouse server 172.29.71.47 to the backup server.

Step Two:

Cd/etc
Vim crontab
Modify the crontab file to continue adding daily backup timed tasks at the end of the file
#SoftServer_47
1 * * * Root cd/home/backup/softserver_47 &&/home/backup/softserver_47/backup_softser ver.sh

Step Three:

After you modify the crontab file, run the following command to take effect:

Service Cron Restart

Synchronize the contents of the folder on the/home/iptv/release/ci_release/dsv1 directory on the 172.29.71.47 server to the backup server daily 1:40.

Related Article

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.