Mustafa Can Yücel
blog-post-1

Backing Up Your Server

Why Backup Your Server

Regularly backing up your virtual private server (VPS) is of paramount importance for several compelling reasons. Firstly, it safeguards your critical data and configurations. A VPS often hosts websites, applications, databases, and other essential resources. By performing regular backups, you protect your data against potential risks such as hardware failures, software glitches, or human errors. In the event of a catastrophic event or system compromise, having up-to-date backups enables swift recovery, minimizing data loss and downtime. Secondly, backups provide an additional layer of security. Cyber threats and attacks continue to evolve, making it crucial to have a backup strategy that includes regular snapshots of your VPS. If your VPS falls victim to a malware infection, ransomware attack, or unauthorized access, you can restore a clean backup, effectively isolating and removing the compromised elements. Lastly, backups offer flexibility and scalability. They allow you to experiment with system changes, software updates, or new configurations, knowing that you can revert to a stable state if needed. Regular backups also simplify the process of migrating to a different VPS provider or upgrading to a more powerful server. By prioritizing regular backups for your VPS, you ensure data integrity, enhance security, and maintain operational resilience in the face of unforeseen circumstances.

What are the options?

Service Provider Snapshots

Some VPS providers have a snapshot feature that allows you to create a backup of your VPS. This feature is usually available through the provider’s control panel or API. While convenient, this option has several drawbacks. Firstly, it is not available for all VPS plans. Secondly, it is not always free. Some providers charge a fee for this service, while others include it in their plans. Thirdly, it is not always possible to schedule snapshots. Some providers only allow manual snapshots, which can be time-consuming and inconvenient. Lastly, snapshots are not always stored on a separate server. If the server hosting your VPS fails, you may lose access to your snapshots. However, it is usually by far the easiest option.

Most of the time, you log in to your provider’s control panel, select your VPS, and click on the snapshot button. The provider will then create a snapshot of your VPS and store it on a separate server. You can then use this snapshot to restore your VPS to a previous state. Most of the time, you are charged per GB of the storage used by your snapshot, per month. This is usually a very cheap option, but it can add up if you have a lot of snapshots.

Timeshift

Timeshift for Linux is an application that provides functionality similar to the System Restore feature in Windows and the Time Machine tool in Mac OS. Timeshift protects your system by taking incremental snapshots of the file system at regular intervals. These snapshots can be restored at a later date to undo all changes to the system.

In RSYNC mode, snapshots are taken using rsync and hard links. Common files are shared between snapshots which save disk space. Each snapshot is a full system backup that can be browsed with a file manager. In BTRFS mode, snapshots are taken using the in-built features of the BTRFS filesystem. BTRFS snapshots are supported only on BTRFS systems having an Ubuntu-type subvolume layout (with @ and @home subvolumes).

Timeshift is similar to applications like rsnapshot, BackInTime, and TimeVault but with different goals. It is designed to protect only system files and settings. User files such as documents, pictures, and music are excluded. This ensures that your files remain unchanged when you restore your system to an earlier date. If you need a tool to back up your documents and files please take a look at the excellent BackInTime application which is more configurable and provides options for saving user files.

Timeshift has a GUI to handle all the operations, however, when you are running a server without a GUI, you can use the command line interface. You can install Timeshift with the following command:

sudo apt install timeshift
Timeshift works with restore points; you can create a restore point with the following command:
sudo timeshift --create --comments "A new backup" --tags D
Tags define specific types of backups. The following tags are available:
  • D: Daily
  • W: Weekly
  • M: Monthly
  • Y: Yearly
  • O: On-demand
To restore a backup, you can use the following command:
sudo timeshift --restore
This command shows you a list of available backups. You can select the backup you want to restore and Timeshift will restore it. It will ask a lot of questions, but you can just press enter to accept the default values, which works 99% of the time.

Note that Timeshift is not a replacement for a full backup solution. It is only meant to protect your system files and settings. You should use a different backup solution to back up your user files. It also uses a lot of disk space, so you should only use it if you have a lot of disk space available.

etckeeper

etckeeper allows the contents of /etc to be stored in a Version Control System (VCS) repository. It integrates with APT and automatically commits changes to /etc when packages are installed or upgraded. Placing /etc under version control is considered an industry best practice, and the goal of etckeeper is to make this process as painless as possible. To install etckeeper, you can use the following command:

sudo apt install etckeeper
The primary configuration file, located at /etc/etckeeper/etckeeper.conf, is relatively uncomplicated. The key setting determines the version control system (VCS) to utilize, with the default configuration of etckeeper being set to employ git. When you install the package, the repository is automatically initialized and committed for the initial time, streamlining the setup process.

By default, the etckeeper automatically commits any uncommitted changes made to /etc daily. This behavior can be turned off by utilizing the AVOID_DAILY_AUTOCOMMITS configuration option. Additionally, the etckeeper will automatically commit changes both before and after package installation. However, for more precise and detailed tracking of changes, it is advisable to manually commit your modifications along with a descriptive commit message using the following command:

sudo etckeeper commit "Reason for configuration change"

To rollback a set of changes, you can use the following command:

sudo etckeeper vcs checkout
This command will restore the last committed version of /etc. If you want to restore a specific version, you can use the following command:
sudo etckeeper vcs checkout <commit>
You can find the commit ID by using the following command:
sudo etckeeper vcs log
For more information, you can check the official website.