FAQ
Upgrades, Downgrades

Backup and Restore Data on Linux

23min

Backup and Restore Data on Linux

In this article, we will explain how to back up and restore data on Linux systems using different tools like tar, rsync, dd, and cloud services such as Google Drive and Amazon S3. The guide covers both the backup and restore procedures for each tool.



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.

Backup Steps:

  1. Open Terminal
  2. To backup 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:

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 another useful tool for backups, allowing you to synchronize data between directories, or even between servers.

Backup Steps:

  1. Open Terminal
  2. To backup 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 backup from a remote server, use:

Bash






Restore Using rsync

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

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

The dd tool is used for making complete backups of disks or partitions (for example, for backing up an operating system or a specific partition).

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:

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 or Amazon S3 for storing backups, the rclone tool allows you to back up and restore data to/from these services.

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