Home
Page

Revised
March 07, 2015

HOW TO
Computer Backup Scripts

There are a lot of very good applications to do computer backups with.   But I did it the hard way.   I wrote my own program.   Why?   So I could learn how to program using bash (Bourne again shell) shell script and how to set up a CRON to schedule the scripts.

You may have another backup system, but may find that the hourly and daily scripts can be of benefit.   They are self cleaning, so there is no attention needed.

Please any corrections, suggestions or general feedback about this page.

Index:

Scripts:

Short Term Incremental:

Hourly Backup:

The hourly script

Daily Backup:

The Daily script

Clean Up:

The Clean Up Script

Incremental Archived:

Weekly Backup:

Script

Monthly Backup:

Script

Full Backup

rsync:

Script.

To DVD:
To External Hard Drive:

Information Sources:

Warnings and Notes:

Scripts:

Short Term Incremental:

Limited to those directories that I may do a lot of changes to during the day.   Such as the directories that contain my web site.   So if I screw up, I can then go back and find the copy that I last saved during that time.   These backups are purged from the system after a few days by a cleanup script.   I usually keep them for 4 to 20 days, then deleted from the system.

Storage should be in a partition that is on a separate hard drive.   For mine, I store the backups in /mnt/backup/running.

Hourly Scripts:

I run this backup every 1 or 2 hours.   But only the likely hours that it will be in use, such as from 7 AM to 9 PM at home and every hour from 6 AM to 6 PM on out Church server.   It is run just a few minutes after the hour.

I commonly back up the /etc, /home and /srv (which contains Samba file server and Apache web pages) directories.   But you can set it up to backup any directory.   Even a directory on another machine that has been mounted.

I used to back up another Microsoft® machine.   But have turned off the backup due to security concerns.   Since you need access to the machine, everyone else has the same access.

Click here to view the hourly script

Daily Scripts:

Run every night, just after midnight . Basically same as the hourly, but I added some other directors such as /root. I are kept these for two or three weeks.

Click here to view the Daily Linux script

For the Microsoft® machine, same as the hourly.   I have turned off the backup due to security concerns.   Since you need access to the machine, everyone else has the same access.

Clean Up:

The hourly and daily backups are saved for only a short time.   Here I have a script to remove these files after a specific period of time.   The cleanup scripts are run before midnight every day.

Click here to view the full Cleanup script

Incremental Archived Backups:

These are weekly and monthly incremental backup that are stored on another media for a year or so.   In the past I have burned these to a CD, then I used an external hard drive for a time.   Currently I am burning these to a DVD once a month.

These backups are placed in it's own directory.

For both weekly and monthly scripts I have a second one that I run to backup a Microsoft machine.   Since there are security problems with Microsoft sharing, I manually turn on the sharing, mount the ¨C-Drive¨, run the script, unmount the ¨C-Drive¨, and finally turn off the sharing.   Yes, there has to be a better way.

Weekly Backup:

Once a week this script runs.

On our Church server, I have set the configuration to capture the changes made in the last week.   But on my home computer I have made it the last two weeks.   This is due to the computer being down due to being out of town.

Click here to view the Weekly script   The weekly and monthly use the same script.

Monthly Backup:

These are run the first day of the month.

Click here to view the Monthly script   The weekly and monthly use the same script.

Full Backups:

The purpose for full backups is mainly for disaster recovery.   To that end, I do not have a good solution, except for hard drive disaster, if you have a second hard drive on your machine, then see rsync below.

The best thing to do is to store your full back ups in a remote location, where fire, tornado, hurican, etc. does not destroy your computer and the back up at the same time.

rsync:

This is run every night.   rsync checks the original and the back up, then makes changes to the back up as needed.   You can also use rsync for storing the back up copy on a remote computer.   rsync handles all the logging in to a remote computer.

Click here to view the rsync script.

To DVD:

Work in progress.

To External Hard drive:

Work in progress.

Information Sources:

Warnings, and Notes:

Script file names end in ".sh".

Script files must have the Execute Permission enabled for it to run.

To learn about writing bash (Bourne again shell) shell script and the commands, a lot of information can be found on Linux Google.   Another source for beginners is "The Linux Terminal - a Beginners' Bash"

When setting "mtime -7" (see below), the -1 includes only the date the script was run.   Hence if you have a -1 and run the script just after midnight, only a few minutes of changes files will be captured.

Set the backup time to twice the frequency.   Example, if you are doing a weekly backup, backup the last 14 days.   If something happens to one of the backups, not all of the data for that week will be lost.

To run the script file manually, just click on the file name in the Konqueror File Manager once.

May sure you use the "if" command.   If the directory can not be accessed, the backup files will be stored in the /root directory.   Hence if you are backing up the /root directory, you are backing up backups.   Then the size of the /root backup will grow and you will run out of hard drive space in your / directory.   Not good.

Do not store the backup files on the same hard drive that you are backing up.   So if a hard drive dies, then all is not lost.

Microsoft uses spaces in some of their directory names.   A very bad practice.   Your script will not run right if that space is included.   I have not found a good answer on how to get around this problem.

Microsoft is funky about upper and lower case letters.   I have not been able to figure out how it works.   So suggest testing to see if it works.

Make sure the backup file that is created is not so large that it will not fit on one CD-ROM.   Also, a large backup file can take a long time to open.   A couple of hundred Mega Bytes can take a long long time to open.

A nice thing about Tar Ball (.tar.gz) files is that they can be opened just like a directory in Konqueror file manager.   You can then find the file needed and drag and drop it to copy or replace the file.

/home on Linux / UNIX and C:\WINDOWS\Profiles on Microsoft directories can get very large.   One reason for this is that an E-Mail Client does on compress or clean up it's e-mail folders.   Make sure that preference is set in the client.


If you have any comments, problems, questions or suggestions, please send me an e-mail at

Updated;   This page was last updated on Mar 07 , 2015 .

Any Browser        Gates Free        Valid XHTML 1.0! Valid CSS!

Linux Logo