Skip to main content

Backup and restore data on Linux

This article explains how to back up and restore data on Linux systems. We cover different tools like tar, rsync, and dd, as well as cloud services such as Google Drive and Amazon S3. The guide covers both the backup and restore procedures for each tool.
Keep a copy outside this VPS and test restoring it. Files copied to another directory on the same virtual disk do not protect you against disk erasure or service deletion. Stop application writes or use an application-consistent backup method; databases should use their supported dump or backup tools.

1. Backup using tar

One of the most commonly used tools for backing up files and directories in Linux is the tar command. It allows you to easily compress files and store them in an archive, helping you save important files and directories for later restoration. You can also use tar for incremental backups by archiving only files that have changed since the last backup. This saves storage space and reduces backup time. Note: tar archives do not include certain metadata like boot records. A common use case is backing up the home directory.

Backup steps

  1. Open Terminal
  2. To back up a specific folder (e.g., /home/user/data), use the following command:
Bash
Explanation:
  • -c: Create a new archive.
  • -v: Show detailed operations.
  • -p: Preserve file permissions.
  • -z: Compress using gzip.
  • -f: Specify the archive file name.

Restore using tar

To restore data from a .tar.gz archive file, use the following command:
Extract into an empty test directory first and inspect the result. Extraction can overwrite matching destination files. However, an ordinary archive does not remove newer files that are absent from the archive, so it is not an exact system rollback. See the GNU tar manual.

Restore steps

  1. Open Terminal
  2. To restore data from a backup file to a specific directory, run the following command:
Bash
Explanation:
  • -x: Extract files from the archive.
  • -v: Show extraction details.
  • -p: Preserve permissions.
  • -z: Decompress with gzip.
  • -C: Specify the destination directory for extraction.

2. Backup using rsync

rsync is a reliable and useful tool for backups, allowing you to sync data between directories, or even between servers. Rsync is commonly used to sync files and directories for backup purposes, ensuring data consistency and integrity.

Backup steps

  1. Open Terminal
  2. To back up data from a specific folder, run the following command:
Bash
Explanation:
  1. -a: Archive mode, preserves file attributes like permissions and timestamps.
  2. -v: Show detailed progress.
  3. -z: Compress data for faster transfer.
To back up from a remote server, use:
Bash

Restore using rsync

To restore data from a backup made with rsync, use the same command structure for restoring files.

Restore steps

  1. Open Terminal
  2. To restore data from a backup directory, run:
Bash
To restore data from a remote server:
Bash

3. Backup using dd

dd copies raw blocks. Its output is a raw disk image, not a bootable ISO installer or a QCOW2 image.
Boot a rescue environment before imaging or restoring the system disk, and keep the source filesystems unmounted so they cannot change during the copy. Store the image on a separate disk or remote storage with enough free space, never on the source disk. During restoration, of= is the disk that will be overwritten completely.
Run lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT and positively identify the source, destination, and their sizes before either command. /dev/sda below is a placeholder example; an EDIS VPS may use /dev/vda or another name. The restore target must be at least as large as the original disk.

Backup steps

  1. Open Terminal
  2. To create a backup of a disk, use:
Bash
Explanation:
  1. if: Input file (the source disk or partition).
  2. of: Output file (backup destination).
  3. bs: Block size (in this case, 64K).

Restore using dd

To restore data from a disk or partition backup created with dd, use the following command for restoring. This restoration process will replace all data on the target disk with the backup image.

Restore steps

  1. Open Terminal
  2. To restore data to the target disk, run:
Bash

4. Backup using cloud services with rclone

If you use cloud services like Google Drive, Amazon S3, or Dropbox for storing backups, you can use the rclone tool. It supports backing up and restoring data to/from these services for off-site backups. Rclone can sync and copy files between your local system and remote locations, and it supports encrypted backups to enhance data security through encryption. When configuring cloud backups, make sure to specify the correct location for your data. If you prefer a graphical interface, GUI programs like Deja Dup are available. Deja Dup (a graphical interface for Duplicity) supports incremental and encrypted backups, and integrates with cloud storage.

Backup steps

  1. Open Terminal
  2. To back up data to a cloud service, use:
Bash

Restore steps

  1. Open Terminal
  2. To restore data from the cloud service, use:
Bash
For the block-copy options used here, see the GNU dd reference.
Last modified on September 30, 2026