System Backup under Linux

application background

The more important directories in the system are /home, etc. Now you want to back up at 2:45am every day, back up the data to /backup, and use tar to package the backup data. How to deal with it?
 
solution
Step 1: Edit the backup script as follows:
[root@localhost backup]# vim /root/bin/backup.sh
 
#!/bin/bash
backdir="/home"
basedir=/backup
[ ! -d "$basedir" ] && mkdir $basedir
backfile=$basedir/backup.tar.gz
tar -zcvf $backfile $backdir
 
Step 2: Edit /etc/crontab for system backup, see the last line for the key code
[root@localhost backup]# vim /etc/crontab
 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
 
# For details see man 4 crontabs
 
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
45 2 * * * root sh /root/bin/backup.sh

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326407838&siteId=291194637