updating backup

This commit is contained in:
Jason S. Evans 2016-03-03 15:29:47 +01:00
parent 9779e5d72d
commit 21917575ab
1 changed files with 32 additions and 16 deletions

View File

@ -73,7 +73,7 @@ All examples in this HOWTO will be performed on fresh installations of https://w
There are three directories that absolutely must be backed up: `/home`, `/var/www`, and `/etc` as well as the MySQL database.
==== Files to be backed up.
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.
@ -82,15 +82,15 @@ The following shell script uses tar to create an archive file on a remotely moun
#!/bin/bash
####################################
#
# Backup to NFS mount script.
# Compress files script
#
####################################
# What to backup.
backup_files="/home /var/spool/mail /etc /root /boot /opt"
backup_files="/home /var/spool/mail /etc /root /boot /opt" // <1>
# Where to backup to.
dest="/mnt/backup"
dest="/mnt/backup" // <2>
# Create archive filename.
day=$(date +%A)
@ -113,19 +113,35 @@ date
# Long listing of files in $dest to check file sizes.
ls -lh $dest
----
<1> The directories listed here will be backed up by this script recursively.
<2> This is the directory where the backup file will be placed at the end.
.$backup_files: a variable listing which directories you would like to backup. The list should be customised to fit your needs.
.$day: 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 date utility.
.$hostname: variable containing the short hostname of the system. Using the hostname in the archive filename gives you the option of placing daily archive files from multiple systems in the same directory.
.$archive_file: the full archive filename.
.$dest: destination of the archive file. The directory needs to be created and in this case mounted before executing the backup script. See Network File System (NFS) for details of using NFS.
.status messages: optional messages printed to the console using the echo utility.
.ar czf $dest/$archive_file $backup_files: the tar command used to create the archive file.
..c: creates an archive.
..z: filter the archive through the gzip utility compressing the archive.
..f: output to an archive file. Otherwise the tar output will be sent to STDOUT.
.ls -lh $dest: optional statement prints a -l long listing in -h human readable format of the destination directory. This is useful for a quick file size check of the archive file. This check should not replace testing the archive file.
==== Backing up MySQL.
This is a simple example of a backup shell script; however there are many options that can be included in such a script. See References for links to resources providing more in-depth shell scripting information.
This step assumes that you already have administrative access to the database that you want to backup. The following command has three parts, the `username`, the `database_to_backup`, and the name of the file to backup.
----
mysqldump -u username -p database_to_backup > backup_name.sql
----
In the following example, the owner is `root` and the database is called `wordpress`.
----
jsevans@26599ca1e943:~$ mysqldump -u root -p wordpress > wordpress.sql
Enter password:
jsevans@26599ca1e943:~$ ls -l wordpress.sql
-rw-rw-r-- 1 jsevans jsevans 1864993 Mar 3 13:28 wordpress.sql
----
After the backup is completed, we can the compress it like we did with the other files.
----
tar czf backup_name.tgz backup_name.sql
----
Now that we have a backup of our website and other important files, where should we keep them?
== Backup storage
"Where should I keep my backups?", is a questions with a lot of different possible answers. It is best to keep a few of the latest backups in an easy to reach place in case they are needed soon.