|
4749.
|
|
|
One of the simplest ways to backup a system is using a <emphasis>shell script</emphasis>. For example, a script can be used to configure which directories to backup, and pass those directories as arguments to the <application>tar</application> utility, which creates an archive file. The archive file can then be moved or copied to another location. The archive can also be created on a remote file system such as an <emphasis>NFS</emphasis> mount.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:21(para)
|
|
4750.
|
|
|
The <application>tar</application> utility creates one archive file out of many files or directories. <application>tar</application> can also filter the files through compression utilities, thus reducing the size of the archive file.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:27(para)
|
|
4753.
|
|
|
#!/bin/bash
####################################
#
# Backup to NFS mount script.
#
####################################
# What to backup.
backup_files="/home /var/spool/mail /etc /root /boot /opt"
# Where to backup to.
dest="/mnt/backup"
# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"
# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo
# Backup the files using tar.
tar czf $dest/$archive_file $backup_files
# Print end status message.
echo
echo "Backup finished"
date
# Long listing of files in $dest to check file sizes.
ls -lh $dest
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
represents a space character.
Enter a space in the equivalent position in the translation.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:38(programlisting)
|
|
4755.
|
|
|
<emphasis>$day:</emphasis> a variable holding the day of the week (Monday, Tuesday, Wednesday, etc). This is used to create an archive file for each day of the week, giving a backup history of seven days. There are other ways to accomplish this including using the <application>date</application> utility.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:81(para)
|
|
4758.
|
|
|
<emphasis>$dest:</emphasis> destination of the archive file. The directory needs to be created and in this case <emphasis>mounted</emphasis> before executing the backup script. See <xref linkend="network-file-system"/> for details of using <emphasis>NFS</emphasis>.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:100(para)
|
|
4763.
|
|
|
<emphasis>f:</emphasis> output to an archive file. Otherwise the <application>tar</application> output will be sent to STDOUT.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:129(para)
|
|
4765.
|
|
|
This is a simple example of a backup shell script; however there are many options that can be included in such a script. See <xref linkend="backup-shellscript-references"/> for links to resources providing more in-depth shell scripting information.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:143(para)
|
|
4768.
|
|
|
The simplest way of executing the above backup script is to copy and paste the contents into a file. <filename>backup.sh</filename> for example. The file must be made executable:
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:153(para)
|
|
4769.
|
|
|
chmod u+x backup.sh
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:158(command)
|
|
4770.
|
|
|
Then from a terminal prompt:
|
|
|
|
(no translation yet)
|
|
|
|
Located in
serverguide/C/backups.xml:160(para)
|