Back up a cPanel server via SSHFS
So you have a cPanel server and want to set up automated, off-site backups, just in case anything should happen? This can be done easily with a FUSE (filesystem in userspace) module called SSHFS, and requires a minimum of setup. SSHFS allows one to mount any remote directory accessible via SFTP to a local filesystem. Cool, huh?
All you really need to accomplish this is access to a server via SSH with sufficient disk space to hold your backups, and the FUSE module available on your server. (Many VPS providers are willing to enable this for you if it is not already enabled)
Notice: The following howto assumes that you are a competent linux/unix administrator. I take no responsibility for any damage or data loss which may be caused by following these instructions.
Step one: Set up a passwordless SSH key on the cPanel server.
First, we need to generate an SSH key:
Be sure you leave the passphrase option blank, or the automatic part won’t work so well . The default options will work fine for this.
Now, you will need to get the public key from the cPanel server that you will be importing:
The above assumes you did not choose a DSA key, or opt to store it in a location other than default. Copy the text that the above command outputs.
Now, move over to your remote/backup server, and run the following:
echo "text you copied from the cPanel server" >> ~/.ssh/authorized_keys
chmod 640 ~/.ssh/authorized_keys
Next, go back to the cPanel server and test to ensure that the public key login works:
If the public key is installed correctly, you will be logged into the remote server without any password prompts.
Step two: install SSHFS
For purposes of this howto, I’m assuming you are using CentOS, in which case you can install sshfs with the following command:
yum install sshfs
Say yes to any dependencies it may prompt you to install.
Step three: Configure the fstab on your cPanel server to mount a backup directory
Assuming you want your backups to go to /backup on the local cPanel server (replacing /path/to/storage with the appropriate path on the remote server):
echo "sshfs#user@remote_server:/path/to/storage /backup fuse noauto,compression=yes,nonempty" >> /etc/fstab
Test this mount with the command “mount /backup” If you receive no errors, the mount should be working correctly.
Step four: Configure the cPanel backup
Visit the address https://_your_cpanel_server_:2087/scripts/backupset
in your web browser, and configure the settings to your liking, making sure to select the following:
Backup Status: Enabled
Remount/Unmount backup drive: Enabled
Bail out if backup drive mount fails: Enabled
Backup destination: /backup
Step five: Profit
Now, every night at 1AM (server time) your server will automatically back up to the remote server via SSH.