Connect with us

Plugin Tips

How to Back Up Multiple WordPress Sites on a VPS

A lot of us are guilty of not maintaining recent backups of our sites, thinking that nothing will go wrong. Unfortunately, a major server crash with data loss can happen when you expect it the least. Most dedicated servers allow easily setup of backups. VPS plans have more limited resources, so you should get a bit more creative. Before getting started, you should know that zipping accounts can put load on your server, so you will want to get priority and other settings right. Here is the command I use to back up all my sites’ public_html directories:

🛠️ Divi Builder drag & drop page builder for WP

nice -n 19 tar –exclude=’*/cache/*’ –exclude=’*/logs/*’ -czf – /home/*/public_html | pv -p -t -e -b -r > /root/backup/wordpress_backup_$(date +%F).tar.gz

Here is what it means:

  • nice -n 19: lowers the CPU priority to avoid affecting server performance.
  • Exclude: this command excludes cache.

You can use this command if you want to limit the number of cores you use, you can use something like this (T3):

nice -n 19 ionice -c2 -n7 tar -cf – /home/*/public_html –exclude=’*/cache/*’ –exclude=’*/wp-content/uploads/*’ –exclude=’*/logs/*’ | pv | xz -5 -T3 > /root/backup/wordpress_backup_$(date +%F).tar.xz

In this case, xz -5 -T3 compresses the archive using XZ at level 2 compression with 3 threads. There are other commands that can get it done with less load or a different level of compression but I have had the best results with this. With pigz, you get parallel zipping to speed up the process. You may have noticed that I am using PV in my command. I am using this tool to monitor the progress. I installed it by using this command:

sudo yum install pv

Finally, you need to have your databases backed up. This command creates a dump for each one. In this case, for all my backups, I created a backup directory to store all the files:

mysqldump -u your_db_user -p your_db_name > /root/backup/db_backup_$(date +%F).sql

If you have cPanel or WHM, you do have the option to set up daily or weekly backups but that can become tricky if you don’t have a lot of storage space on your main drive.

Continue Reading
You may want to check out:
*some of our articles and lists include affiliate links to fund our operations (e.g. Amazon, Elegant Themes, Envato). Please read our disclaimer on how we fund Exxponent.
You may also like...
Click to comment

More in Plugin Tips

To Top