#readwise
# Linux Fundamentals - Backup and Restore

## Metadata
- Author: [[Hack The Box]]
- Full Title: Linux Fundamentals - Backup and Restore
- URL: https://academy.hackthebox.com/module/18/section/2095
## Summary
Linux offers various tools for backing up and restoring data, such as Rsync, Duplicity, and Deja Dup. Rsync is efficient for transferring only changed files, while Duplicity adds encryption for extra security. Deja Dup provides a user-friendly interface for easy backup and restoration. Encrypting backups ensures that sensitive data is protected from unauthorized access.
## Highlights
Rsync is an open-source tool that allows for fast and secure backups, whether locally or to a remote location. One of its key advantages is that it only transfers the portions of files that have changed, making it highly efficient when dealing with large amounts of data. Rsync is particularly useful for network transfers, such as syncing files between servers or creating incremental backups over the internet. ([View Highlight](https://read.readwise.io/read/01jmjgp0exqzk8refm3de78y70))
---
Duplicity is another powerful tool that builds on Rsync, but adds encryption features to protect the backups. It allows you to encrypt your backup copies, ensuring that sensitive data remains secure even if stored on remote servers, FTP sites, or cloud services like Amazon S3. Duplicity provides an extra layer of security while maintaining Rsync's efficient data transfer capabilities. ([View Highlight](https://read.readwise.io/read/01jmjgpjfb5eb0164pc5bcp2d2))
---
Rsync is like a fast-moving transport that only carries what's new or changed, making it the ideal way to send updates to a remote vault. Duplicity is a high-security safe that not only stores the treasure but also locks it with a complex code, ensuring no one else can access it. Deja Dup is a simple, accessible safe that anyone can operate, while still offering the same level of protection. Encrypting your backups adds an additional lock on your safe, ensuring that even if someone finds it, they can't get inside. ([View Highlight](https://read.readwise.io/read/01jmjgqph06tvskybm0se5q4az))
---
For users who prefer a simpler, more user-friendly option, Deja Dup offers a graphical interface that makes the backup process straightforward. Behind the scenes, it also uses Rsync, and like Duplicity, it supports encrypted backups. Deja Dup is ideal for users who want quick, easy access to backup and restore options without needing to dive into the command line. ([View Highlight](https://read.readwise.io/read/01jmjgr4nhz73tef6e9545b2vj))
---
```sh
rsync -av /path/to/mydirectory user@backup_server:/path/to/backup/directory
```
This command will copy the entire directory (`/path/to/mydirectory`) to a remote host (`backup_server`), to the directory `/path/to/backup/directory`.
The option `archive` (`-a`) is used to preserve the original file attributes, such as permissions, timestamps, etc., and using the `verbose` (`-v`) option provides a detailed output of the progress of the `rsync` operation.
We can also add additional options to customize the backup process, such as using compression and incremental backups. We can do this like the following:
```sh
rsync -avz --backup --backup-dir=/path/to/backup/folder --delete /path/to/mydirectory user@backup_server:/path/to/backup/directory
```
With this, we back up the `mydirectory` to the remote `backup_server`, preserving the original file attributes, timestamps, and permissions, and enabled compression (`-z`) for faster transfers. The `--backup` option creates incremental backups in the directory `/path/to/backup/folder`, and the `--delete` option removes files from the remote host that is no longer present in the source directory. ([View Highlight](https://read.readwise.io/read/01jmjgvpatqe5h93n6pgmp01ks))
---
If we want to restore our directory from our backup server to our local directory, we can use the following command:
```sh
rsync -av user@remote_host:/path/to/backup/directory /path/to/mydirectory
```
([View Highlight](https://read.readwise.io/read/01jmjgw8fgpbjq9qe7cyh099zj))
---