Latest "rsync & rsnapshot" files
Workshop » Reference Section » Grimoires » IT » Platforms » Linux » Packages » rsync & rsnapshot

How to backup a WordPress site via SSH

To make a complete local backup of a remote WordPress install over SSH, you need to perform two distinct steps:

  1. Download the files (using rsync).
  2. Export and download the database (using mysqldump piped through ssh).

Here is the step-by-step guide.

Prerequisites
  • SSH Access: You need the username, host (IP or domain), and password (or SSH key) for the remote server.
  • WordPress Path: You need to know where WordPress is installed (e.g., /var/www/html or /home/user/public_html).
  • Database Credentials: You will need the database name, user, and password. (I will show you how to find these below).
Step 1: Find Database Credentials (Optional)

If you don't know your database login details, run this command to read them from your remote wp-config.php file: ssh user@remote-server.com "cat /path/to/wordpress/wp-config.php" | grep 'DB_'

Note the DB_NAME, DB_USER, and DB_PASSWORD for Step 2.

Step 2: Download the Database (SQL Dump)…
Workshop » Reference Section » Grimoires » IT » Platforms » Linux » Packages » rsync & rsnapshot

Speeding up rsnapshot (rsync) backups by removing wildcard paths from exclude

I removed a bunch of wildcard paths from rsnapshot.conf's exclude, and suddenly tonight my backup ran in a few minutes instead of taking over a day like it usually does.

Interesting, I've been looking off and on for at least the better part of a year for ways to lighten the load of rsnapshot's under-the-hood rsync backup commands, which reliably took up about half my CPU power almost continuously, and never found this tip before. You can see, plenty of wildcard paths removed, plus a few other things.

Here's a diff, rsnapshot.conf before changes (<) vs after (>):
< verbose 1
---
> verbose 4
120c120
< loglevel 2
---
> loglevel 4
143a144,146
> rsync_short_args -Wa
> #-W is transfer whole files without prescan, recommended for performance by https://serverfault.com/questions/639458/rsync-taking-100-of-cpu-and-hours-to-complete
> #NOTE: if you set the above short…

Workshop » Reference Section » Grimoires » IT » Platforms » Linux » Packages » rsync & rsnapshot

Resolving an rsnapshot error — “rsync: –delete does not work without –recursive (-r) or –dirs (-d). rsync error: syntax or usage error (code 1) at main.c(1795)”

I discovered rsnapshot hadn't run in a few days. Checking /etc/rsnapshot.log, I found every recent day had this:

rsync: --delete does not work without --recursive (-r) or --dirs (-d). rsync error: syntax or usage error (code 1) at main.c(1795) [client=3.2.7]

A few days ago I had added the line rsync_short_args -W to /etc/rsnapshot.conf in an effort to get rsync to run without putting such a load on my system. Removing this and running rsnapshot -v hourly from the command line shows that without it, the first line of the rsync command was /usr/bin/rsync -ax --delete --numeric-ids --relative --delete-excluded \, but with it, the first line was /usr/bin/rsync -Wx --delete --numeric-ids --relative --delete-excluded \.

Changing the line rsync_short_args -W to rsync_short_args -Wa, with an a flag explicitly included, solved the problem. Apparently specifying custom short flags overrides at least one of the default flags.

Also: remember, when you run an…

Workshop » Reference Section » Grimoires » IT » Platforms » Linux » Packages » rsync & rsnapshot

Post-migration steps when migrating or restoring Linux from backup

There are intentionally vague broad steps, here just as a reminder to myself; best to look specific instructions for each of these steps up at restore time for the particular system you're restoring to.

A.) Backups should include all user data. Depending on who you ask, that's either:
1.) The entire filesystem except /dev/*, /proc/*, /sys/*, /tmp/*, /run/*, /mnt/*, /media/*, /lost+found (which can be pulled from a complete filesystem backup with rsync -avhP --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt/olddrive/ /mnt/netdrive/)
2.)/home, /etc (except /etc/passwd and /etc/groups, these have useful information to back up but may conflict if written to a new install), /usr/local, /opt, /root, /var (exluding /var/tmp, /var/run/, /var/lock, or /var/spool except you DO want /var/spool/cron/crontabs/)

B.) After copying all the above to the new or restored disk, you need to update /etc/fstab with the new disk UUIDs.

C.) Install GRUB Bootloader.

D.) If you're using LUKS encryption, set that…

Workshop » Reference Section » Grimoires » IT » Platforms » Linux » Packages » rsync & rsnapshot

Fastest way to delete a large, deep directory in Linux

Per numerous references around the web, to delete /path/to/directory-to-delete/:

 cd /path/to/ mkdir empty_dir rsync -a --delete empty_dir/ directory-to-delete/ rm -r empty_dir rm -r directory-to-delete 

Disclaimer: this is for my own reference, not recommended for your use. Use it at your own risk. If I am wrong—and I may be—these commands can do tremendous damage to your system.

Workshop » Reference Section » Grimoires » IT » Platforms » Linux » Packages » rsync & rsnapshot

Reducing rsnapshot or rsync resource usage

I've had sporadic problems with clearing the WP cache causing the server to return 520 errors for a few minutes. Usually other sites on the same server are fine, it's specific to this vhost. Logging in via SSH, checking with htop, rsync is usually hogging most of the cpu. Restarting the fpm and then restarting Apache restores the website.

According to https://www.claudiokuenzler.com/blog/361/rsnapshot-backup-reduce-high-load-with-ionice, the big bottleneck with rsync, which rsnaphot runs on, is i/o, not cpu, and rsync can actually tie up i/o such that a web server won't respond to http requests. This can be solved by making the rsnapshot command in crontab ionice -c 3 [rsnapshot command] instead of just the rsnapshot command, which tells rsync not to wait until the disk is idle before trying to access it. So I did. In fact, I made it nice -n 19 ionice -c 3 [rsnapshot command] although…