How to set up automated backups for VPS and Dedicated server

Creating a website is just the start of the journey. Once you’ve built your website, you’ll need to keep it up-to-date, back up your data, and keep it safe by preventing unauthorized access.  
A regular backup is the best option for website restoration if any issues occur. You can simply roll back to the last working version. You should also have a current backup before making major changes to your site, such as updating software, installing plugins, or other maintenance.

For the owners of VPS/Dedicated Servers with the Complete management, we create full server backups for you. Feel free to read more about the server management types for VPS and Dedicated Servers.

When backing up your site, you will need to consider where to save the website data. Your first option is to store your archived content on a home PC or external storage device such as an external hard drive or thumb drive. There are also cloud-based backup services that can safely encrypt and store your files.

WHM offers a storage monitoring tool in the backup menu. We will explain how this works further on in this guide.


Manual backups

Automated backups


Manual backups


The simplest way to perform a manual backup is just to download a compressed set of files representing your theme and design files as well as your content database. To do this, you can use the Compress function in the cPanel File Manager:



The phpMyAdmin option allows you to download your databases as a .sql file (read more about phpMyAdmin here). We recommend that you perform backups of the website's database regularly, as all of your site’s posts and pages are stored there. This database is essential in the website restoration process.



If you are hosting cPanel accounts as a reseller, you may offer your clients the option to create their own backups using the in-built cPanel menus Backup and Backup Wizard:



The instructions on how to use these options can be found here. The functionality of the menus is very similar, and both allow full and partial backups creation and restoration. These menus do not automate the process, but, they do offer a number of options for the manual backups.


Automated backups


The Backup Configuration WHM menu allows you to set up automated backups. It can be found in the Backup section on the left-side WHM menu.



The Backup Status has to be set to Enabled in order to activate automated backups:




Global Settings


If you choose to store the backup on the same server, pay attention to the Backup Type in Global Settings. It offers three different options:
  • Compressed – Ideal for saving space, but the backup process will be slower.
  • Uncompressed – A quicker backup, but one that uses more disk space.
  • Incremental – Only saves the files and the configuration that have changed since the last backup.



The Minimum Free Disk Space Check is necessary if you want to control storage usage on the server. If this setting is not modified, the backup will be created regardless of how much free space is available, and you might run out of space on the server.

You can choose between megabytes (actual space allocated for the backups) and percentage (limits backup storage allocation to a proportionate amount of server space). Choosing a percentage ensures other services on the server have enough space to run safely.

For example, MySQL needs at least  5% disk space free in order to run. Other modules and services will also need free disk space. Thus, we recommend you leave at least 10-15% of a disk space secured.



Maximum Destination Timeout should be used to specify the time in which you expect the backup to be generated. It should allow enough time to handle the largest file, otherwise, the process will be aborted. The maximum value is 50000 seconds here.



The same goes for the Maximum Restore Timeout which is used for the backup restoration purposes.
The top value is 86400.




Scheduling and Retention


Create your backup schedule using the Scheduling and Retention menu.



There are three scheduling options to choose from:
  • Daily backups that allow you to specify which day of the week backups should be made.
  • Weekly backups are performed every 7 days starting with the day the backup creation was enabled.
  • Monthly allow you to create backups once a month.

We recommend trying daily or weekly backups with a moderate retention of 1-2 copies. Retention refers to how many previous backups will be kept before the oldest backup gets overwritten by a newly-created one.

PLEASE NOTE: These backups consume disk space when saved on the server, so it is important to save only as many copies as you think you will need.

The Strictly enforce retention, regardless of backup success checkbox means that the old backup will be deleted and replaced with the latest one. Even if the new backup is incomplete, corrupted or empty (due to being impossible to generate, not having enough time or space, etc.) it will still replace the old one. We recommend disabling this option to make sure that working older backups are not overwritten with a newer invalid one.


Files


In the Files section, you can choose what content you wish to save.



We recommend always having these two checkboxes selected at all times:
  • Backup Accounts (This is needed for cPanel restoration purposes.)
  • Backup System Files (This option offers a possibility to restore the whole server.)

As for other features under Backup Accounts, it is up to the server owner to decide if these are needed or not.

Clicking on the Select Users button near the Backup Accounts, will open a second tab labelled Backup User Selection. It is possible to check accounts that are currently added to the server backup and add or remove any of them.




Databases


In the Databases section, it is possible to create a backup of separate .sql files or the whole MySQL server directory.



Backing up the MySQL databases per account will allow you to restore individual cPanel accounts.

The entire MySQL directory contains the whole MySQL service of the server and all the related settings.

It is ideal to select both options, because it will protect your server and websites if the MySQL service itself goes down as well as if an individual website experiences issues.


Configure the Backup Directory


The Configure the Backup Directory section allows you to specify the path on the server where the backups will be saved. This is also where you can establish an external location for the backups.



By default, the /backup directory is located on the server itself, and is not accessible from any cPanel for security reasons. The content is available either via SSH directly or in the Backup Restoration menu without opening the file as it is.


Additional Destinations


It is possible to save automated full backups to an external storage device. This might be another server purchased for this purpose specifically or another cloud service. It is important to remember that on the third-party storage you need to manually remove outdated backup archives. If there is no space at that location, the WHM/cPanel will not be able to save a new copy there.

All this can be configured in the Additional Destinations section. You can set up certain popular storage options with the help of the drop-down menu and the Create New Destination button:



The section supports setting up a custom external storage. We recommend that this setup be performed by a professional developer or a network admin. Sensitive settings and security permissions need to be carefully checked, and misconfiguration may result in failed backups.

In our example, we use the Google Drive option. Choosing a preset configuration option like Google Drive requires knowing the details for that storage (in this case, the  Google API and the account credentials):



The following fields should be filled in:
  • Destination Name – a name to identify this backup rule on your server
  • Transfer System Backups to Destination – check this option if you prefer that backups are removed from the server and only saved to Google Drive
  • Folder – an optional setting to specify the folder to which the backups are saved. If left blank, the system will use the home directory
  • Client ID – the ID of your Google Account
  • Client Secret – a Google Client secret that is generated in the Google account

For a better understanding of the Google Drive setup, we advise getting acquainted with the Google API as it is required for the full use of Google Drive and using the client ID and secret.

The configured destination must be validated to ensure the successful access. Make sure to do so and save all the changes:

Before proceeding, select 'Compressed' type of backups at 'Global Settings'. It is not recommended to upload files via FTP uncompressed.

Select FTP option from the dropdown menu 'Destination type' and press 'Create New Destination' button:

The following fields should be filled in:

Destination Name – a name to identify this backup rule on your server (E.g 'FTP storage').

Transfer System Backups to Destination – check this option if you prefer that backups are removed from the server and only saved to FTP storage.

Backup Directory – an optional setting to specify the folder to which the backups are saved. If left blank, the system will use the home directory. We would recommend leaving it blank.

Remote Host - target FTP IP address or FQDN (e.g server1.example.tld)

Port - Port for the FTP protocol on the target server. Usually it is '21'.

Remote Account Username - The account name for the connection to the remote server or storage.

Remote Password - Password string for accessing remote storage or server.

Timeout - The amount of time before the connection times out. Indicated in seconds.

Once the details were entered, press the 'Save and Validate Destination' button.

In case the details were entered correctly and FTP storage is available, the following message should be seen:

Success:

The validation for the “Destination Name” destination succeeded
.

How to set up automated backups for Dedicated Servers without a control panel using the Duplicity software

In order to install the Duplicity, epel-release must be installed. Please perform the following command via shell from root user:

yum install -y epel-release

The following output is expected:

After that, perform the following command to install Duplicity:

yum install -y duplicity

The following output is expected:

In order to backup the directories with Duplicity to the remote FTP storage, the following details are required:

  • The IP of the storage server or FQDN
  • The username for the FTP storage
  • The FTP_Password for the FTP storage

The aforementioned details were sent with your Welcome Email.

In our tutorial, we will back up the /etc and /var/log directories to the remote FTP storage.

With Duplicity, we will utilize the “full” backups mode. We will not use incremental backups since FTP storage is not efficient for that task.

In order to perform backups of folders using Duplicity, the following should take place:

The following command will only back up

/etc

/var/log

Additional directories are specified via “--include” flag:

FTP_PASSWORD=XXXXXXXXXXXX duplicity full --include /home --include /etc --include /var/log --exclude '**' / ftp://2039-992200@phxnas01.dcops.tech/ --no-encryption

Definitions:

FTP_PASSWORD - password for the FTP storage that was provided in the Welcome email.

Duplicity - binary, software in question.

full - mode of the backups.

--include - key for the included folders.

--exclude - key for the excluded folders.

**-specifies to ignore all folders, except included ones.

/- directory to the backup.

ftp://2039-992200@phxnas01.dcops.tech/- represents FTP storage in the format of protocol://username@hostname/.

--no-encryption- key for disabling GPG backup encryption.

The following output is expected when the command is executed (password is blurred for security reasons):

Listing backups

To list the created backups, feel free to issue the following command, XXXXX is to be replaced with your FTP password and 2039-9922 with your FTP user:

FTP_PASSWORD=XXXXXXXXXXXXX duplicity collection-status ftp://2039-992200@phxnas01.dcops.tech

Definitions

collection-status - lists the backup at the specified URL/storage.

You may see the following output when running the command against your storage server:

Please note that the test server already performed the backups so the amount of the backups listed is higher than the initial run.

Restoring the backups:

It is not recommended to overwrite an existing folder that was archived previously. In our example, we will extract the latest archive from storage to the /home/temp_backup folder, so it can be used later for restoration purposes.

To restore the latest backup, run the following command, replacing the variables with the ones that match to your environment (FTP host, user, ftp password):

FTP_PASSWORD=XXXXXXXXXXX duplicity restore ftp://2039-992200@phxnas01.dcops.tech/ /home/temp_backups --no-encryption

Definitions:

Restore - defines the restoration function for the software.

/home/temp_backups - the temporary directory that is used for restored files.

--no-encryption - key for disabling GPG backup encryption.

The following output is expected when the restore is successful:

Backups removal:

In case there is a need to remove backups but leave only a single copy, the following command should be issued:

FTP_PASSWORD=XXXXXXXXXX duplicity remove-all-but-n-full 1 ftp://2039-992200@phxnas01.dcops.tech/ --no-encryption --force

Definitions:

remove-all-but-n-full - specifies the removal of all copies except the latest one.

1 - specifies the amount of the backups to keep.

--force - key that specifies the forced action.

You may see the following output, depending on the amount of the backups performed:

Running backups via cron

In order to automate backups, make sure to add the command to the cronjobs of the root user. You can do this by adding the command to the crontab in your system.

To enter the edit mode for the crontab, please issue the following command:

crontab -e -u root

The default editor for the crontab is Vi/Vim, thus you will need to hit ‘I’ button (Insert) for the insert mode and append the following command to the end of the file:

0 0 * * 0 FTP_PASSWORD=XXXXXXXXXX duplicity full --include /etc --include /var/log --exclude '**' / ftp://2039-992200@phxnas01.dcops.tech/ --no-encryption > /root/dub_log 2>&1

After that, press ‘ESC’ to enter command mode, press ‘Shift + : ’ and type ‘wq!’ to save and exit.

That should save the entry in the crontab.

Definitions:

0 0 * * 0 - values that specify to run the cron every week on Sunday.

> - redirects output to the specified file.

/root/dub_log - the target redirect of the cron output.

2>&1 - redirect the errors to the output.

This concludes our how-to guide on using the Duplicity software.

For more additional options or custom configurations please refer to Duplicity’s official page..

How to configure data backups with the Interworx control panel

In order to configure the backups for your data at Interworx control panel, follow the guide described in this paragraph.

Access your Siteworx interface via the following URL:https://IP:2443/siteworx/

'IP' should be replaced with the IP of your Dedicated Server.

You may receive the following message depending on which browser you use:

Google Chrome:

Click on 'Advanced' and 'Proceed to IP (unsafe)' buttons:

Firefox:

Click on 'Advanced...' and 'Accept the Risk and Continue' buttons:

It is a safe location, since the browser is giving a warning due to a self-signed SSL certificate used for Nodeworx service for the IP address..

Once you are prompted with the login screen, please input your administrator login details in the corresponding fields:

Make sure to use the 'Email', 'Password','Domain' that were used for the SiteWorx account creation at the Nodeworx panel.

Once the SiteWorx panel has been accessed, navigate to 'Backups' menu, following 'Backup now' button:

At the 'Backup now' menu, select backup type 'Full backup' and backup where you see 'FTP':

Click on the 'Continue' button to proceed.

Fill in the details from your FTP storage at the corresponding fields:

Definitions

E-mail status to: - specifies the email address for the notifications regarding backup status.

Domain options: - specifies whether to backup only the main domain or all of the domains. For the complete backup, we select the 'Multi Domain' option.

Backup where: - the remote destination for the backup storage. In our example, we will use “FTP”.

Path: - specifies the remote storage path where the data would be saved. Usually it is '/'

Username: - the remote storage username.

Password: - the remote storage password.

Confirm Password: - the password confirmation remote storage.

Hostname: - the host name to access the remote storage.

Port: - FTP port. We will use default '21'.

Passive Mode:- Specifies which FTP mode to use. In most cases, the passive mode should be set “on”.

Extensions to exclude: - defines which extensions will not be backed up by Siteworx. You can check more details about this by hovering over the [?] sign next to it.

As soon as the details are filled in, please click on the 'Backup' button to create the backup:

Restoring backups

In order to restore the full backup created by Interworx, you'll need to download the backup archive from the FTP storage by using the “ftp” command line tool. In order to do that, you’ll need to access the server over SSH to perform these command line actions.

Now we’ll provide a guide on how to check the backups via the FTP. You can access the FTP storage via command line using the following commands:

Run 'ftp IP or FQDN' in order to connect to storage via shell. Once prompted for the username, enter the 'Username' from remote storage:

Hit the 'Enter' button.

Enter the password from remote storage in the 'Password:' field. It would stay blank for the security purposes:

Here’s an indication of the successful FTP login:

230 User YourUserHere logged in

Now issue the 'ls' FTP command to list the current directory:

As you can see, we have previously created the 'test1.localhost+full-Feb.26.2021-09.30.51.tgz'.

Now change the local directory for the FTP client to /home by issuing the following command:

lcd /home

In order to download file, issue the following command

get test1.localhost+full-Feb.26.2021-09.30.51.tgz

This will download the file 'test1.localhost+full-Feb.26.2021-09.30.51.tgz' to the /chroot/home location at your server.

Now hit the 'Ctrl D' combination to exit the FTP command line tool.

Once the file has been downloaded and restore the account with overwrite option, type in the following terminal command:

/home/interworx/bin/import.pex --archive=/path/to/.tgz --control-panel=siteworx --ip-address=YourIP --force

Definitions:

/home/interworx/bin/import.pex - the Interworx utility that refers to restoration/import.

--archive= - specifies the restoration file. /path/to/.tgz should be replaced with the path to your backup file. In our example, we used /home/test1.localhost+full-Feb.26.2021-09.30.51.tgz

--control-panel= - the control panel that was used for the backup creation. In our case, the value is siteworx.

--ip-address= - specifies the IP address that should be used for the account and domain names within.

--force -specifies the overwrite flag, which overwrites all of the existing account data from the backup.

Once the restoration is complete, you will be able to see the following output at the end of the report:

For additional details or custom configurations, please refer to the official Interworx support article.

How to access the FTP storage via the ftp command line

In order to be able to use the “ftp” command line tool, please log in to the server over SSH. If you have the cPanel/WHM control panel installed, navigating the “Terminal” menu in the cPanel/WHM will work, too.

In order to access the remote FTP storage, we will need your FTP username, your FTP host, and your FTP password.

At your terminal window, please issue the following command:

ftp phxnas01.dcops.tech

Please note that all of the actions are performed on the server.

Definitions:

ftp - invokes the ftp command line utility

Phxnas01.dcops.tech - the remote FTP storage address (either IP address or hostname)

The following output is expected:

Type in your username in the next field and hit the “Enter” button:

2039-992200 is our FTP test username. Make sure to specify your own FTP username.

In the “Password” field, copy and paste your password from your FTP storage.

The following is an indication of a successful login:

Once you are logged in, you can request the available commands by issuing the “?” command:

In our tutorial, we will use the following basic commands: lcd, pwd, dir, cd, put, delete, get, bye

lcd - returns the local directory of the active session if used, without arguments. Otherwise, “lcd /home” will change the local working directory from /root to /home on your server.

lcd home

pwd - prints the current working directory on the remote FTP server. Usually it is “/”:

dir - prints the content of the current working directory on the remote FTP server:

In our directory example, we had 1 directory “account.”

cd - changes the working directory on the remote FTP server. In our example, we had directory 2021-02-25 on the FTP storage so we will use it as argument to the “cd” function:

If you see the “250 CWD command successful” message, this indicates that command was successful.

put - uploads the specified file to the remote FTP storage. The name of the transferred file is passed as the first argument.

Next, we will place the file named “version” into the 2021-02-25 directory. The next command will be issued in order to perform that:

put version

The following output is expected:

Please note that the file should exist on the local working directory at your server (/home/version - example).

delete - removes the file from the remote FTP storage:

In our example, we removed the “version” file that we uploaded earlier.

get - will download the specified file to your local working directory from the remote FTP storage:

stats.txt was used as an argument to the “get” command, the file to be downloaded.

In order to exit the FTP command line utility, enter the “bye” command:

This concludes our short FTP tutorial!

Feel free to refer to the official documentation of the FTP project.




That’s it!

Updated
Viewed
19283 times

Need help? We're always here for you.