Shell-written data backup, Incremental backup, and full backup

Source: Internet
Author: User
 

 

The company's Linux server uses a common desktop and lacks a disaster recovery mechanism. The company stores a large amount of data on this server. Once a fault occurs, the consequences are unimaginable. Therefore, it is necessary to effectively back up important data of this machine. After several days of data collection, I finally compiled my own Linux script to implement a complete monthly backup and daily Incremental backup, the packaged file contains a detailed list of files backed up on the current day for future recovery. Incremental Backup stores data within 90, and data earlier than 90 will be automatically deleted. All backup files are saved locally and automatically backed up to another host through the network.

The detailed script content is as follows:

#! /Bin/sh

Date = 'date + % F-% H'

Host = "192.168.16.17"

Id = "admin"

PW = "123456"

Ftpdir = "days"

Baktime = 'date -- date = '90 days ago '+ % Y-% m-% d'

If ['date + % d' = '1']

Then

Filename = "linux$.tar.gz"

Basedir = "/mnt/SMB/bak/monthly"

ZL = ""

Bakdir = "/data/Arca/work/Linux"

Else

Filename = "bak1_date.tar.gz"

Basedir = "/mnt/SMB/bak/days"

ZL = "-T/tmp/filelist-2.daily"

Bakdir = ""

Fi

Find/data/Arca/work/Linux/-type F-mtime-1-print> $ bakdir/filelist. Daily

CAT/tmp/filelist. Daily | grep '/. [C. H] $'>/tmp/filelist-2.daily

# Echo $ baktime

# Tar-n' $ baktime' zcvf $ basedir/$ filename $ bakdir

Tar $ zl-czvf $ {basedir}/$ filename $ {bakdir}

# Starting FTP to Send File

CD $ basedir

FTP-N> "$ basedir"/"$ FILENAME". log 2> & 1 <EOC

Open $ host

User $ ID $ pw

Binary

CD $ ftpdir

Mput $ filename

Bye

EOC

Test-e bak1_baktime.tar.gz & Rm-F Bak $ baktime * | ECHO not fonud this files

Store the file in/etc/cron. In the daily directory, this directory is the directory that the system regularly runs. This script runs once a day and completes the current score on the first day of each month. Incremental backup is performed on other dates. some files are not important, so select only. c. h file for backup.

 

This script is not complete yet. If the script cannot be sent to the remote host, you cannot determine it. I will modify the problem below.

 

After a simple modification, the script can synchronize the local data and Master/Slave Data. It is widely used.

 

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.