Useful SSH commands for backing up and restoring your website
Taking backups of your website files and databases is hugely important when either updating files, adding extensions or to safeguard any work you might be doing on your server. Using SSH will speed up the process of creating a backup of your data to the manual method of using cPanel in your browser.
Making a database dump in the root of your website directory
After connecting to via SSH to your server, cd to the root of your website. Then past in the below command making sure to replace the highlighted strings with your database information. After this has been entered you will also be asked for your database user password, so make sure you have that handy.
mysqldump -p -u username database_name > dbname.sql
Restoring your database from your backup on the server
If you need to restore you database from the backup you have made using the instructions above, make sure yo are in the root of your website and enter the below command again making sure to change the strings to match your information. Again, you will be asked for the database user password, so make sure you have it ready.
mysql -u username -p tablename < backupfilename.sql
Backup all files and directories
Obviously you will need to take a backup of for files as well as the databases from your site To make a backup of all of the files and directories, connect via SSH and cd to the root of your website. Once there you can run the below command, make sure to swap out the red string with your prefered backup name.
tar -vcf backup-name.tar .
TIP: When moving around into different directories via SSH, you can print out all of the files and directories in the current directory you are in so you can be sure you are in the right place. To do this simply type ls