Skip to content

Instantly share code, notes, and snippets.

@YourFriendCaspian
Created September 6, 2017 04:53
Show Gist options
  • Save YourFriendCaspian/02b7c96e6a933190fb4e829df892f096 to your computer and use it in GitHub Desktop.
Save YourFriendCaspian/02b7c96e6a933190fb4e829df892f096 to your computer and use it in GitHub Desktop.
Full and Incremental Backup Script Instructions
## Automating backups with tar ##
It is always interesting to automate the tasks of a backup.
Automation offers enormous opportunities for using your Linux server to achieve the goals you set.
The following example below is our backup script, called backup.cron.
his script is designed to run on any computer by changing only the five variables:
COMPUTER
DIRECTORIES
BACKUPDIR
TIMEDIR
BACKUPSET
We suggest that you set this script up and run it at the beginning of the month for the first time,
and then run it for a month before making major changes.
In our example below we do the backup to a directory on the local server BACKUPDIR,
but you could modify this script to do it to a tape on the local server or via an NFS mounted file system.
Create the backup script backup.cron file,
touch /etc/cron.daily/backup.cron
Example 33-1. Backup directory of a week
Here is an abbreviated look of the backup directory after one week:
total 22217
-rw-r--r-- 1 root root 10731288 Feb 7 11:24 deep-HOMEDIR-01Feb.<b class="command">tar</b>
-rw-r--r-- 1 root root 6879 Feb 7 11:24 deep-HOMEDIR-Fri.<b class="command">tar</b>
-rw-r--r-- 1 root root 2831 Feb 7 11:24 deep-HOMEDIR-Mon.<b class="command">tar</b>
-rw-r--r-- 1 root root 7924 Feb 7 11:25 deep-HOMEDIR-Sat.<b class="command">tar</b>
-rw-r--r-- 1 root root 11923013 Feb 7 11:24 deep-HOMEDIR-Sun.<b class="command">tar</b>
-rw-r--r-- 1 root root 5643 Feb 7 11:25 deep-HOMEDIR-Thu.<b class="command">tar</b>
-rw-r--r-- 1 root root 3152 Feb 7 11:25 deep-HOMEDIR-Tue.<b class="command">tar</b>
-rw-r--r-- 1 root root 4567 Feb 7 11:25 deep-HOMEDIR-Wed.<b class="command">tar</b>
drwxr-xr-x 2 root root 1024 Feb 7 11:20 last-full
Important: The directory where to store the backups BACKUPDIR, and the directory where to store time of full backup TIMEDIR must exist or be created before the use of the backup-script, or you will receive an error message.
If you are not running this backup script from the beginning of the month 01-month-year, the incremental backups will need the time of the Sunday backup to be able to work properly. If you start in the middle of the week, you will need to create the time file in the TIMEDIR. To create the time file in the TIMEDIR directory, use the following command:
[root@deep] /# date +%d%b < /backups/last-full/myserver-full-date
Where /backups/last-full is our variable TIMEDIR wherein we want to store the time of the full backup, and myserver-full-date is the name of our server e.g. deep, and our time file consists of a single line with the present date i.e. 15-Feb.
Make this script executable and change its default permissions to be writable only by the super-user root 755.
[root@deep] /# chmod 755 /etc/cron.daily/backup.cron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment