This is a backup script mybackup. Sh I am using.
Running properly in RedHat Linux 7.2
Mybackup. Sh
#! /Bin/sh
Umount/mnt/bak
Mount/dev/sdb1/mnt/bak
If ['date + % d' = '01'] # complete backup on the first day of every month
Then
Bakdir = "/mnt/bak/daybak/month/" 'date + % m % d'
ZL = "" # complete backup
Else
Bakdir = "/mnt/bak/daybak/" 'date + % d'
ZL = "-n" 'date + '% Y-% m-01 00:00:01 ''; # differential backup
# ZL = "-n" 'date-d'-1 Day' + '% Y-% m-% d 00:00:01 ''# daily Incremental Backup
Fi
Tmpbakdir =$ {bakdir} TMP
Rm-RF $ {tmpbakdir}
Mkdir $ {tmpbakdir}
Tar "$ {ZL}"-CZF $ {tmpbakdir}/www. tgz/var/www/html
Tar "$ {ZL}"-CZF $ {tmpbakdir}/etc. tgz/etc
Tar "$ {ZL}"-CZF $ {tmpbakdir}/MySQL. tgz/var/lib/MySQL
Tar "$ {ZL}"-CZF $ {tmpbakdir}/home. tgz/home
Tar "$ {ZL}"-CZF $ {tmpbakdir}/name. tgz/var/Name
Rm-RF $ bakdir
MV $ tmpbakdir $ bakdir
Umount/mnt/bak
Put mybackup. Sh in/etc/cron. Daly to implement monthly cyclic differential/Incremental backup.
To facilitate data recovery, I used differential backup. If I want to save space, I can use daily total backups. However, it will be troublesome to restore data, in addition, you can easily change the above script to weekly loop.
The other method of Incremental backup is to use the find command,
For example, only files modified one day ago are backed up.
Find/var/www-type F-mtime-1-print>/tmp/filelist.txt
Tar-CZ-T/tmp/filelist.txt-F/mnt/bak/www. tgz