Restic backups store changes over time as a series of de-duplicated ‘snapshots’ of the server. Any given snapshot can restore any given file to as it was at that time. If you make a lot of changes to data, the size of the backups in Object Storage can be quite large, and sometimes you want to tell restic to forget those changes. You can remove snapshots from the backups, and restic will automatically figure out what data needs to be preserved to keep a complete backup of the system, but discard the changes in those snapshots. Hostwinds Cloud Backups defaults to 60 snapshots being stored, but that can be changed.
To remove previous snapshots, only two commands are required to be ran, “forget” and “prune” the details of how to do so are below –
As with any interaction with restic, you must first initialize the repo to perform actions within restic, to do so follow this guide.
# restic snapshots password is correct ID Date Host Tags Directory ---------------------------------------------------------------------- 37f632eb 2018-02-22 11:32:43 hwkb.hostwindsdns.com all_databases.sql b923eed6 2018-02-22 11:45:17 hwkb.hostwindsdns.com database_dump.sql ---------------------------------------------------------------------- 2 snapshots
Using the above example, there are 2 backups, to remove a snapshot you simply need to know the ID of the snapshot, which is the first item in the available snapshots above.
In this example, we will be removing the second snapshot, which has the ID of b923eed6
# restic forget b923eed6 password is correct storage ID 9babef79 removed snapshot b923eed6
Next, you will need to run restic prune, this removes the data referenced in the snapshot that was removed from the restic repository, cleaning up unreferenced data.
An example of this can be seen below –
# restic prune password is correct storage ID 9babef79 counting files in repo building new index for repo [2:16] 100.00% 11981 / 11981 packs repository contains 11981 packs (345057 blobs) with 56.676 GiB processed 345057 blobs: 0 duplicate blobs, 0B duplicate load all snapshots find data that is still in use for 1 snapshots [0:00] 100.00% 1 / 1 snapshots found 2 of 345057 data blobs still in use, removing 345055 blobs will remove 0 invalid files will delete 11979 packs and rewrite 0 packs, this frees 56.664 GiB counting files in repo [0:00] 100.00% 2 / 2 packs finding old index files saved new indexes as [70561784] remove 11 old index files [1:12] 100.00% 11979 / 11979 packs deleted done
It is advised to run restic check after you prune, to ensure you are aware if there are any internal data structures of the repository damaged.
The command being ran, and its output would be similar of that below –
# restic check password is correct create exclusive lock for repository storage ID e7155fe8 load indexes check all packs check snapshots, trees and blobs no errors were found
Now, when you view your backup’s snapshots, the entry you have removed will no longer be listed.
# restic snapshots password is correct ID Date Host Tags Directory ---------------------------------------------------------------------- 37f632eb 2018-02-22 11:32:43 hwkb.hostwindsdns.com all_databases.sql ---------------------------------------------------------------------- 1 snapshots