Skip to content

Instantly share code, notes, and snippets.

@rothkj1022
Last active November 24, 2020 23:23
Show Gist options
  • Save rothkj1022/8e96f7c627103d393c2e8330ebffca59 to your computer and use it in GitHub Desktop.
Save rothkj1022/8e96f7c627103d393c2e8330ebffca59 to your computer and use it in GitHub Desktop.
Instructions to mirror important config files to backup folder that can be backed up remotely.

WHM/cPanel Config Files Backup Instructions

Last Updated 2019-06-18 by Kevin Roth

Mirror the current configuration files on the server to the backup folder in order to make remote backups of the system configuration. See this link for source of backup folders and files.

Make directories

# mkdir -p /backup/config/etc/cpanel/ea4
# mkdir -p /backup/config/etc/csf
# mkdir -p /backup/config/etc/apache2/conf.d
# mkdir -p /backup/config/etc/apache2/conf
# mkdir -p /backup/config/etc/my.cnf.d
# mkdir -p /backup/config/etc/nginx
# mkdir -p /backup/config/opt/cpanel/ea-php71/root/etc
# mkdir -p /backup/config/opt/cpanel/ea-php72/root/etc
# mkdir -p /backup/config/opt/cpanel/ea-php73/root/etc
# mkdir -p /backup/config/usr/local/apache/conf
# mkdir -p /backup/config/var/cpanel/conf/apache
# mkdir -p /backup/config/var/cpanel/secdatadir
# mkdir -p /backup/config/var/cpanel/templates/apache2_4

Make target files:

We must use mount --bind instead of symbolic links, otherwise rsync/aws will ignore these files. We have to create target files before we can bind the actual files to them.

# touch /backup/config/etc/cpupdate.conf
# touch /backup/config/etc/crontab
# touch /backup/config/etc/csf/csf.conf
# touch /backup/config/etc/exim.conf
# touch /backup/config/etc/fstab
# touch /backup/config/etc/my.cnf
# touch /backup/config/etc/stats.conf
# touch /backup/config/etc/wwwacct.conf
# touch /backup/config/etc/wwwacct.conf.shadow
# touch /backup/config/var/cpanel/cpanel.config
# touch /backup/config/var/cpanel/modsec_cpanel_conf_datastore

Mount folders & files

Symlinked folders will not sync to Amazon S3, so we mount them using fstab.

Set up fstab to auto mount folders on boot:

# nano /etc/fstab
Paste the following at the end of the file:
# Mount folders for backing up config
/etc/cpanel/ea4	/backup/config/etc/cpanel/ea4	none	ro,defaults,bind	0 0
/etc/apache2/conf.d	/backup/config/etc/apache2/conf.d	none	ro,defaults,bind	0 0
/etc/apache2/conf	/backup/config/etc/apache2/conf	none	ro,defaults,bind	0 0
/etc/my.cnf.d	/backup/config/etc/my.cnf.d	none	ro,defaults,bind	0 0
/etc/nginx	/backup/config/etc/nginx	none	ro,defaults,bind	0 0
/opt/cpanel/ea-php71/root/etc	/backup/config/opt/cpanel/ea-php71/root/etc	none	ro,defaults,bind	0 0
/opt/cpanel/ea-php72/root/etc	/backup/config/opt/cpanel/ea-php72/root/etc	none	ro,defaults,bind	0 0
/opt/cpanel/ea-php73/root/etc	/backup/config/opt/cpanel/ea-php73/root/etc	none	ro,defaults,bind	0 0
/usr/local/apache/conf	/backup/config/usr/local/apache/conf	none	ro,defaults,bind	0 0
/var/cpanel/secdatadir	/backup/config/var/cpanel/secdatadir	none	ro,defaults,bind	0 0
/var/cpanel/templates/apache2_4	/backup/config/var/cpanel/templates/apache2_4	none	ro,defaults,bind	0 0
# Mount files for backing up config
/etc/cpupdate.conf	/backup/config/etc/cpupdate.conf	none	ro,defaults,bind	0 0
/etc/crontab	/backup/config/etc/crontab	none	ro,defaults,bind	0 0
/etc/csf/csf.conf	/backup/config/etc/csf/csf.conf	none	ro,defaults,bind	0 0
/etc/exim.conf	/backup/config/etc/exim.conf	none	ro,defaults,bind	0 0
/etc/fstab	/backup/config/etc/fstab	none	ro,defaults,bind	0 0
/etc/my.cnf	/backup/config/etc/my.cnf	none	ro,defaults,bind	0 0
/etc/stats.conf	/backup/config/etc/stats.conf	none	ro,defaults,bind	0 0
/etc/wwwacct.conf	/backup/config/etc/wwwacct.conf	none	ro,defaults,bind	0 0
/etc/wwwacct.conf.shadow	/backup/config/etc/wwwacct.conf.shadow	none	ro,defaults,bind	0 0
/var/cpanel/cpanel.config	/backup/config/var/cpanel/cpanel.config	none	ro,defaults,bind	0 0
/var/cpanel/modsec_cpanel_conf_datastore	/backup/config/var/cpanel/modsec_cpanel_conf_datastore	none	ro,defaults,bind	0 0
Test fstab mappings:

IMPORTANT! Make sure to test your mappings and adjust your fstab for any errors, or your server will not boot!

# mount -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment