summaryrefslogtreecommitdiff
path: root/backup-delete-all-but-last-N-snapshots-from-restic.sh
blob: ec53e965fdb8704a9b6ca9e720b8fc854e0f9fc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh
[ -z "$1" ] && {
	printf "Provide number of snapshots to keep\n"
	exit 1
}
[ $1 -gt 0 ] || {
	printf "%s doesn't look like a positive number\n" "$1"
	exit 1
}
restic snapshots -c
printf "Will delete these snapshots:\n" "$1"
restic snapshots -c | awk 'NR>2 && !/^-+$/ && !/^[0-9]* snapshots$/ {print $1}'|head -n -"$1"
printf "Proceed? [y/N]\n" "$1"
read answer
[ "$answer" = "y" ] && {
	restic snapshots -c | awk 'NR>2 && !/^-+$/ && !/^[0-9]* snapshots$/ {print $1}'|head -n -"$1"|xargs -n 1 restic forget
	restic prune
}