Skip to content

Commit 9090bd4

Browse files
authored
Document data restoration process for new server
Added detailed instructions for restoring data from a backup onto a new server, including setup, restore methods, and file ownership correction.
1 parent a5761b8 commit 9090bd4

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

how-to/restore-data.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Restore data from one server's backup onto a completely new server. The process involves setting up your script on the new server and pointing it to the existing backup repository on your Hetzner Storage Box.
2+
3+
-----
4+
5+
## 1. Set Up the New Server
6+
7+
First, install and configure the backup script on new VPS.
8+
9+
* **Install Dependencies**: Follow the "Prerequisites" section in the `README.md` to install `restic`, `jq`, `curl`, and other required tools on VPS2.
10+
* **Download Your Script**: Copy your entire script directory (containing `restic-backup.sh`, `restic-backup.conf`, etc.) from VPS1 to a suitable location on VPS2, like `/root/scripts/backup/`.
11+
* **Configure SSH**: Set up passwordless SSH access from VPS2 to your Hetzner Storage Box, just as you did for VPS1. This involves generating a new SSH key on VPS2 (`sudo ssh-keygen`) and adding the public key to your Storage Box's settings. Update `/root/.ssh/config` on VPS2 with the `Host storagebox` alias.
12+
* **Copy the Password File**: Securely copy your Restic password file (e.g., `/root/.restic-password`) from VPS1 to the exact same path on VPS2. Ensure its permissions are set to `400`.
13+
* **Configure the Script**: Edit `restic-backup.conf` on VPS2. The `RESTIC_REPOSITORY` and `RESTIC_PASSWORD_FILE` should be the same as on your old server. You can leave the `BACKUP_SOURCES` empty for now, as you are only restoring.
14+
15+
-----
16+
17+
## 2. Run the Restore
18+
19+
There are two main options for restoring the data, depending on your needs. Before you begin, it's helpful to see what data is available.
20+
21+
### A. Find the Data You Need
22+
23+
First, list the available snapshots to find the one you want to restore from. The `--snapshots` flag will show you all backups, including those from your old `vps1`.
24+
25+
```bash
26+
sudo ./restic-backup.sh --snapshots
27+
```
28+
29+
Once you have a snapshot ID (or if you just want the latest one), you can list its contents to find the exact path of the directory you want to restore.
30+
31+
```bash
32+
# List all contents of the latest snapshot
33+
sudo ./restic-backup.sh --ls latest
34+
35+
# List only the contents of a specific directory within the snapshot
36+
sudo ./restic-backup.sh --ls latest "/path/to/directory"
37+
```
38+
39+
### B. Choose a Restore Method
40+
41+
* **For smaller restores or if you want to stay connected**: Use the interactive `--restore` wizard. It's user-friendly and shows you a dry run before starting.
42+
```bash
43+
sudo ./restic-backup.sh --restore
44+
```
45+
* **For large restores**: Use the non-interactive `--background-restore` command. This is ideal for restoring a large amount of data without needing to keep your terminal open.
46+
```bash
47+
# Restore the latest snapshot to /mnt/data-from-vps1 in the background
48+
sudo ./restic-backup.sh --background-restore latest /mnt/data-from-vps1
49+
```
50+
51+
-----
52+
53+
## 3. Correct File Ownership
54+
55+
After the restore is complete, the files will be owned by `root` because the script runs with `sudo`. If you restored the data to a user's home directory, the script's built-in logic will attempt to automatically correct the ownership.
56+
57+
If you restored to a different location (like `/srv/www`), you'll need to manually change the ownership. For example, to give ownership to the `www-data` user:
58+
59+
```bash
60+
sudo chown -R www-data:www-data /srv/www
61+
```

0 commit comments

Comments
 (0)