Restic backup guide

Restic backup guide

desp

Earlier I've used duply.net, but switched to restic. Why?
Because - very easy to configure (like git commit/git init)
Has rclone support (upload backups to any preferred cloud storage)
Fast, effective in terms of space and deduplication
Easy to configure/setup/roll-out
Works stable without complexity.
Mini guide how to use restic with rclone


1. Install restic & rclone 


apt-get update && apt-get install restic -y && curl https://rclone.org/install.sh | sudo bash


2. Setup rclone for your cloud storage integration.


rclone config


Follow the instructions
Then check that you properly set up your remote folder by rclone 
rclone ls myremotefolder:
Where myremotefolder: it's how you called your rclone remote connection
If you see files or can copy files there (https://rclone.org/commands/rclone_copy/)
everything will be fine.


3. Now need to prepare what exactly you will backup. 


If you backup /home folder, prepare some small script to do dumps of your MySQL setup.


Just example of the script:

```

#!/bin/bash
mysqldump -uroot <your_db> > /home/sql/your_db.sql
exit 0

```

4. Now, do your first MySQL dump to your /home/sql/ folder by the command above.

5. Now it's time to initialize restic 


What is "initialization"? It's the same terminology as in git. When you "tell restic that let's start to track this folder now," restic will start to create a cache of all files for future work with all of them.

restic --repo rclone:myremotefolder:MY_BACKUPS_FOLDER/ init

That command means next:


- restic -> call program

- --repo with parameter: "hey restic, i want to work with next repo."

- "rclone:myremotefolder:MY_BACKUPS_FOLDER/" means repo name and path. 
I.E. 
> rclone:myremotefolder:

means -> use rclone to connect to myremotefolder: 


Then initialize backups on my remotefolder to MY_BACKUP_FOLDER. If the folder does not exist, -> program will create the folder "MY_BACKUP_FOLDER" for you.


- and last command: "init"

This command is the same as `git init` You said: "initialize the backups here."
As you see, you do not yet say anything about your files that need to be backup. 


6. How to make backups? Simply:


restic --repo rclone:myremotefolder:MY_BACKUPS_FOLDER/ backup /home/


By this command, you saying: Hey restic, please use repository for backups that we earlier created "rclone:myremotefolder:MY_BACKUPS_FOLDER/"

and **do backup** in this repository next folder "/home"

And restic will start backup. The first backup will be slow, but the next ones will be okay.


7. How to organize backup.sh script?


Example:

```

#!/bin/bash
# here is password of backup repo (encryption)
# This pass needed to restic to encrypt/decrypt/read files
export RESTIC_PASSWORD=MY_RESTIC_REPO_PASSWORD_FOR_FILES
# doing SQL dumps of databases
mysqldump -u root my_backup_db --lock-tables=false > /home/sql/my_backup_db.sql
# Here we doing backup using restic to google drive (remember, need init repo first (guide above)).
# restic --repo rclone:myremotefolder:MY_BACKUPS_FOLDER/ init
restic --repo rclone:myremotefolder:MY_BACKUPS_FOLDER/ backup /home
# backup done, let's remove /home/sql/* data
rm -rf /home/sql/*
# done
exit 0

```

8. How to check what backups do I have?

https://restic.readthedocs.io/en/latest/050_restore.html


Report Page