| How to clever backup website data |
Print this page
|
Well-designed backup technology may save up a lot of time and money. Usually, website backup contain two major parts: database backup and website directory backup. About database backup you can read here.
In that article we will speak about website directory backup.
If you are web developer who rent web space from a web hosting provider — you can said: "I do not need backup, because my provider do it for me and guaranty website directory content recovery". But, what about version control, if you are decide to upgrade you website and save old website directory content? Just for any case.
First, intuitive solution is connect to website directory using FTP and download whole directory to home/work computer.
There are some disadvantages here:
- It takes some time to download whole website directory.
- Downloaded files are not compressed, so if your website is big — you need a lot of disk space to store whole website directory.
- When you try to restore website, it will takes the some time to upload content back.
- After uploading you will have to reestablish files and directories permissions.
Therefore, the best solution for website directory backup is to archive whole directory into one compressed file at web server side, with saving all files and directories permissions and after that downloading it to home/work computer or anywhere else.
TAR program plus GZIP compression is one of the best solution to do that. To easy run that command on web server side you need access to shell on web server. If you don't have access to shell at web server — you can use Web Console.
First of all, you must make sure that you have access to TAR, to do that — execute following shell command:
If TAR is available, you should see output like this:
GNU 'tar' saves many files together into a single tape or disk archive,
and can restore individual files from the archive.
Usage: tar [OPTION]... [FILE]...
...
It means, that you can use TAR command.
If it doesn't work you can try to run TAR using full path:
shell> /usr/bin/tar --help
shell> /usr/sbin/tar --help
shell> /usr/local/bin/tar --help
shell> /usr/local/sbin/tar --help
shell> /bin/tar --help
shell> /sbin/tar --help
Old versions of TAR doesn't support compression and just pack files and directories to one file. To save up disk space you can use GZIP compression to make backup file more compact.
To find out that your TAR support 'z' option (GZIP compression), just search for following text in "TAR --help" output:
Archive format selection:
...
-j, --bzip2 filter the archive through bzip2
-z, --gzip, --ungzip filter the archive through gzip
-Z, --compress, --uncompress filter the archive through compress
...
If your TAR does not support 'z' option (GZIP compression), for GZIP compression your can use GZIP program.
To make sure that you have access to GZIP just execute following shell command:
If GZIP is available, you should see output like this:
gzip [VERSION]
...
usage: gzip [-cdfhlLnNrtvV19] [-S suffix] [file ...]
...
It means, that you can use GZIP command.
If it doesn't work you can try to run GZIP using full path:
shell> /usr/bin/gzip --help
shell> /usr/sbin/gzip --help
shell> /usr/local/bin/gzip --help
shell> /usr/local/sbin/gzip --help
shell> /bin/gzip --help
shell> /sbin/gzip --help
To unpack GZIP compressed archive, if your TAR does not support 'z' option (GZIP compression), your can use GUNZIP program.
To make sure that you have access to GUNZIP just execute following shell command:
If GUNZIP is available, you should see output like this:
gunzip [VERSION]
...
usage: gunzip [-cdfhlLnNrtvV19] [-S suffix] [file ...]
...
It means, that you can use GUNZIP command.
If it doesn't work you can try to run GUNZIP using full path:
shell> /usr/bin/gunzip --help
shell> /usr/sbin/gunzip --help
shell> /usr/local/bin/gunzip --help
shell> /usr/local/sbin/gunzip --help
shell> /bin/gunzip --help
shell> /sbin/gunzip --help
Below you can find instructions to backup website directory:
- Backup command for TAR that support 'z' option will looks like that:
shell> tar -zcvf ./archive_name.tar.gz ./web_dir
Example you can see at following screenshot:
 Screenshot: Packing directory into archive using TAR
And for TAR that doesn't support 'z' option backup command will looks like that:
shell> tar -cvf - ./web_dir | gzip -c > archive_name.tar.gz
Example you can see at following screenshot:
 Screenshot: Packing directory into archive using TAR + GZIP
That commands will pack directory "./web_dir" into compressed archive "archive_name.tar.gz" with saving all files and directories permissions. That two commands make exactly the same archive file.
Now archive "archive_name.tar.gz" can be moved to home/work computer or anywhere else. Using that archive file you can easy restore whole your website directory with files and directories permissions at any time.
Below you can find instructions to restore website directory:
- Transfer archive with backup to your website.
-
Unpack command for TAR that support 'z' option will looks like that:
shell> tar -zxvf ./archive_name.tar.gz
Example you can see at following screenshot:
 Screenshot: Unpacking archive using TAR
And for TAR that doesn't support 'z' option unpack command will looks like that:
shell> gunzip < ./archive_name.tar.gz | tar -xvf -
Example you can see at following screenshot:
 Screenshot: Unpacking archive using TAR + GUNZIP
That commands will unpack archive "archive_name.tar.gz" with saving all files and directories permissions. Result of execution of that two commands will be exactly the same.
Using TAR program plus GZIP compression for website directory backup/restore gives following advantages:
- Backup and restore command executes very fast, because running on server.
- Backup is compressed and do not waste disk space.
- Security permissions on the files and directories reestablished automatically in restoration process.
To find more information about tar, gzip, gunzip command-line parameters just execute following shell commands:
shell> tar --help
shell> gzip --help
shell> gunzip --help
Or if you want to read manuals — execute following shell commands:
shell> man tar
shell> man gzip
shell> man gunzip
/ Any republication of website content required direct track back link /
|