Creating a full website backup
Oct 22, 2024 | Andrew Wilson
- how-to
- website backup
- disaster recovery
While the majority of hosting packages come with some form of backups included, there are many benefits to creating and storing personal backups of your web applications, including:
- The ability to choose the point in time that the backup is taken - for instance a short time before a large update to the applications source code is being made, providing a recent point-in-time snapshot of the site should breakages occur during development.
- Verification of the backup’s integrity - manual backups can be inspected/restored locally to ensure that recovery is possible should a catastrophic failure occur.
- Speed of recovery - sometimes only a single or small subset of files need to be restored and uploading these from a local backup can be done in a matter of minutes. Host provided restoration of backups may require extracting a subset of files from a full snapshot of the account/server which can add time to the operation.
Creating a usable backup is a matter of compressing the applications source code and its database to an archive, which can then be downloaded and stored locally. This can be achieved by:
Logging into your server via SSH
While you can create backups using FTP, logging in via SSH allows you to create a single downloadable archive directly on the server
Identifying the directory that your application is stored in
On M.D.G. IT hosted VPS services this will typically be /var/www/html/<website domain>
Using the tar command to create an archive
1
tar -czvf /home/web/app_backup.tar.gz /var/www/html/mysite.com.au/
It is not always necessary to back up the entire codebase for backup purposes. For example if the application stores caches or logs, this would result in larger backups to download/restore and offer no real benefit. Excluding subdirectories from the archive can be done by adding an --exclude flag and the path to the directories to be excluded to the command, e.g.:
1
tar --exclude="/var/www/html/mysite.com.au/var/log --exclude="/var/www/html/mysite.com.au/var/cache" -czvf /home/web/app_backup.tar.gz /var/www/html/mysite.com.au/
Create and compress a database backup
1
mysqldump my_db_name | gzip > /home/web/database_backup.sql.gz
You will now have two files created in your home directory - app_backup.tar.gz
and database_backup.sql.gz
which can be downloaded locally via SFTP using a client like FileZilla.
You may also like:
The M.D.G. IT support team have become aware of an issue with the eWay payment gateway module breaking on upgrade to Magento versions 2.4.6 and higher...
Oct 22, 2024