![]() The cron daemon allows the execution of scripts, or commands, at a specified time and date.Ĭron is configured through entries in a crontab file. The cron utility can be used to automate the script execution. This is a great way to test the script to make sure everything works as expected. The file must be made executable: chmod u+x backup.sh The simplest way of executing the above backup script is to copy and paste the contents into a file. ![]() Executing the Script Executing from a Terminal See References for links to resources providing more in-depth shell scripting information. This is a simple example of a backup shell script however there are many options that can be included in such a script. This check should not replace testing the archive file. ![]() This is useful for a quick file size check of the archive file. Ls -lh $dest: optional statement prints a -l long listing in -h human readable format of the destination directory. Otherwise the tar output will be sent to STDOUT. Z: filter the archive through the gzip utility compressing the archive.į: output to an archive file. Tar czf $dest/$archive_file $backup_files: the tar command used to create the archive file. Status messages: optional messages printed to the console using the echo utility. The directory needs to be created and in this case mounted before executing the backup script. $archive_file: the full archive filename. Using the hostname in the archive filename gives you the option of placing daily archive files from multiple systems in the same directory. $hostname: variable containing the short hostname of the system. There are other ways to accomplish this including using the date utility. This is used to create an archive file for each day of the week, giving a backup history of seven days. $day: a variable holding the day of the week (Monday, Tuesday, Wednesday, etc). The list should be customized to fit your needs. $backup_files: a variable listing which directories you would like to backup. # Long listing of files in $dest to check file sizes. Tar czf $dest/$archive_file $backup_files #!/bin/bashīackup_files="/home /var/spool/mail /etc /root /boot /opt"Įcho "Backing up $backup_files to $dest/$archive_file" The archive filename is determined using additional command line utilities. The following shell script uses tar to create an archive file on a remotely mounted NFS file system. tar can also filter the files through compression utilities, thus reducing the size of the archive file. The tar utility creates one archive file out of many files or directories. The archive can also be created on a remote file system such as an NFS mount. The archive file can then be moved or copied to another location. For example, a script can be used to configure which directories to backup, and pass those directories as arguments to the tar utility, which creates an archive file. One of the simplest ways to backup a system is using a shell script. Multi-node configuration with Docker-Composeĭistributed Replicated Block Device (DRBD)
0 Comments
Leave a Reply. |