Back Up Your Linux Server Before a Reinstall

A reinstall from the Client Area erases all disks of the server, so everything you want to keep has to be copied to another place first: another server, a storage service or your own computer. This page shows how to do it with rsync over SSH and with rclone. The commands were tested on Ubuntu 26.04 LTS; run them as root.


1. Decide What to Keep

  • your data, for example /home, /var/www and the folders of your programs;
  • the settings in /etc and the files of root in /root;
  • databases, saved as files first (see below);
  • the list of installed packages, to install them again later:
apt-mark showmanual > /root/packages.txt

Databases change while they run, so do not copy their folders. Save them with their own tool, for example for MariaDB or MySQL:

mysqldump --all-databases --single-transaction --routines --events > /root/databases.sql

The --single-transaction option makes a consistent copy of InnoDB tables. Do not change table definitions while the dump runs; tables using other engines need their own consistent backup procedure.

For Docker, the data is in the folders and volumes you gave to the containers; copy those (see Docker on Your Linux Server).

2. Copy With rsync to Another Server

You need another server with SSH and enough space. Below it is 198.51.100.20 with the user store, SSH on port 2222; use your own address, user and port (without -p for port 22). Log in with a key, so that the copy runs without a password: Log In to Your Linux Server With an SSH Key.

Create the destination folder on the other server first:

ssh -p 2222 store@198.51.100.20 'mkdir -p backups/server1'
rsync -aAXH --info=progress2 --rsync-path="rsync --fake-super" -e "ssh -p 2222" /etc /root /home /var/www store@198.51.100.20:backups/server1/

The options keep the permissions, links and extended attributes (-aAXH) and show the progress. --fake-super keeps the owner of every file even though the user on the other side is not root; without it, all files come back owned by that user. For example, 300 MB are copied in about 3 seconds.

Run the same command again just before the reinstall: rsync then copies only what has changed. For example, when one file has changed, the second run copies that one file instead of all 1700.

Check the copy on the other server:

ssh -p 2222 store@198.51.100.20 du -sh backups/server1/*

3. Or Copy With rclone

rclone copies to more than 40 kinds of storage: another server via SFTP, S3-compatible storage, Backblaze B2, Google Drive, OneDrive and others. Install it and set up a storage place ("remote"):

apt install rclone
rclone config

rclone config asks for the type of storage and its login, step by step. For another server via SFTP you can also create the remote in one line:

rclone config create mybackup sftp host 198.51.100.20 port 2222 user store key_file /root/.ssh/id_ed25519

Copy a folder and compare the copy with the original:

rclone copy /var/www mybackup:backups/www --progress
rclone check /var/www mybackup:backups/www

rclone check ends with 0 differences found when the copy is complete.

ℹ rclone and file owners

rclone copies the content of files, not their owners and permissions. That is fine for data such as websites, videos or documents. For /etc and other system files, use rsync.


4. Restore After the Reinstall

Connect to the reinstalled server, set up the SSH key for the other server again, and copy back what you need, folder by folder:

rsync -aAXH --rsync-path="rsync --fake-super" -e "ssh -p 2222" store@198.51.100.20:backups/server1/www/ /var/www/

Do not copy the whole old /etc over the new system. Restore single files from it, for example the configuration of your web server, and compare them first.

Install your packages again from the list:

apt install $(cat /root/packages.txt)

Load the databases again with mysql < /root/databases.sql.

Back Up Every Night

Disks can fail at any time, not only before a reinstall. To run the copy every night at 03:00, open the list of scheduled jobs of root with crontab -e and add one line (with your own address, user and folders):

0 3 * * * rsync -aAXH --delete --rsync-path="rsync --fake-super" -e "ssh -p 2222" /etc /root /home /var/www store@198.51.100.20:backups/server1/

--delete removes files from the copy that you deleted on the server, so the copy stays the same size as your data. A copy like this is a mirror: if you delete a file by mistake, it is gone from the copy after the next night too. For several versions back, use a backup program such as restic or borg.


Related Guides

View all Linux guides

Was this answer helpful? 0 Users Found This Useful (0 Votes)