Making regular backups is crucial for any system administrator. Terrible things happen and data gets lost. This may be due to hackers, programing errors, hardware failures or bugs in new code. If you have a website, you need a backup.
There are WordPress plugins which automatically create backups for you. Backing up a WordPress database and website from the linux command line is also easy to do.
The first step to backing up a WordPress website from the linux command line is to backup the database. WordPress uses the MySQL database. To backup a MySQL database you will want to run the
mysqldump
You can backup the database anywhere you like, but I usually do it inside WordPress directory, as I can then easily add both to the compressed tar.gz backup I make. Once backed up I delete the database backup from the WordPress directory.
The command to backup the database should look something like this:
mysqldump -u USER -p DATABASE > BACKUP.sql
where USER is the database username, DATABASE is the name of the WordPress database you want to backup and BACKUP.sql is the name of the backup file you are creating. The above command will prompt you for your MySQL password and then create the backup.
Once you have the WordPress database backed up you need to create a compressed file of the database backup along with all the other WordPress data. What I do is combine the WordPress directory and the MySQL backup into a single tar.gz file. I then move this file to a different server where I keep all my backups.
To create a tar.gz compressed back up you use the command:
tar -zcvf BACKUP.tar.gz DIRECTORY
Where BACKUP.tar.gz is the name of the compressed WordPress backup file you are creating and DIRECTORY is the name of the directory you are backing up.
Once you have this backup.tar.gz file made, be sure to move it somewhere secure. A different server or a flash drive or somewhere far away from your existing WordPress website. The last thing you want to happen is have your backup get destroyed when your websites runs into trouble.