| Simple Backup Shell Script |
|
The following shell script uses tar to create an archive file on a remotely mounted NFS file system. The archive filename is determined using additional command line utilities. #!/bin/sh
This is a simple example of a backup shell script. There are large amount of options that can be included in a backup script. See the section called “References” for links to resources providing more in depth shell scripting information. Executing the ScriptExecuting from a TerminalThe simplest way of executing the above backup script is to copy and paste the contents into a file. backup.sh for example. Then from a terminal prompt: sudo bash backup.sh This is a great way to test the script to make sure everything works as expected. Executing with cronThe cron utility can be used to automate the script execution. The cron daemon allows the execution of scripts, or commands, at a specified time and date. cron is configured through entries in a crontab file. crontab files are separated into fields: # m h dom mon dow command
To add or change entries in a crontab file the crontab -e command should be used. Also, the contents of a crontab file can be viewed using the crontab -l command. To execute the backup.sh script listed above using cron. Enter the following from a terminal prompt: sudo crontab -e
Add the following entry to the crontab file: # m h dom mon dow command The backup.sh script will now be executed every day at 12:00 am.
For more in depth crontab options see the section called “References”. Restoring from the ArchiveOnce an archive has been created it is important to test the archive. The archive can be tested by listing the files it contains, but the best test is to restore a file from the archive.
References
|
||||||||||