-
-
Save moritzdietz/b08dee72e803868c70c18e3fde3f7df2 to your computer and use it in GitHub Desktop.
Simple and ugly Bash script that creates a restic repository and creates hourly snapshots for a whole calendar year. This is for the ones who want to play around with restic forget policies. ¯\_(ツ)_/¯
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Creating a testing repository | |
echo "Creating a restic testing repository at ~/restic-testing-repo" | |
export RESTIC_REPOSITORY="$(echo $HOME)/restic-testing-repo" | |
export RESTIC_PASSWORD='foo' | |
# Change the file or folder you want to backup here | |
backup="$(echo $HOME)/Desktop" | |
# Initializing the repo | |
# The additional argument is for restic build with additional debug capabilities. See https://forum.restic.net/t/script-for-creating-a-test-repository/312/2 | |
# If this command fails for you, you didn't build restic yourself with the debug argument. | |
# This argument below heavily reduces the amount of time when making this testing repository. | |
# Be aware of the warning! | |
restic init --insecure-kdf | |
echo "WARNING: do not use repositories created this way in any production setting!" | |
echo "" | |
echo "" | |
echo "Starting to back up $backup in 8 seconds..." | |
sleep 8 | |
i=1 | |
months=1 | |
while [[ $months -lt 13 ]]; do | |
days=1 | |
while [[ $days -lt 32 ]]; do | |
hour=0 | |
while [[ $hour -lt 24 ]];do | |
if [[ $months -lt 10 ]]; then | |
if [[ $days -lt 10 ]]; then | |
if [[ $hour -lt 10 ]];then | |
restic backup -q "$backup" --time "2017-0$months-0$days 0$hour:00:00" 2>/dev/null & | |
((i++)) | |
#echo "2017-0$months-0$days 0$hour:00:00" | |
# This float resembles 1% of 8929 which is the sum of all executed times of the command above. | |
# This does not represent the actual snapshots taken. Days that are not in the calendar will be skiped by restic but won't be detected in this script. | |
while [[ -e /proc/$! ]]; do | |
echo XXX | |
echo $i | awk '{ printf "%.0f\n", $1*0.01119946242580356142905140553253 }' | |
echo "This will take a while! We're now @ $(ps aux | grep [r]estic| awk {'printf ("%s %s", $16, $17)'})" | |
echo XXX | |
done | |
else | |
restic backup -q "$backup" --time "2017-0$months-0$days $hour:00:00" 2>/dev/null & | |
((i++)) | |
#echo "2017-0$months-0$days $hour:00:00" | |
while [[ -e /proc/$! ]]; do | |
echo XXX | |
echo $i | awk '{ printf "%.0f\n", $1*0.01119946242580356142905140553253 }' | |
echo "This will take a while! We're now @ $(ps aux | grep [r]estic| awk {'printf ("%s %s", $16, $17)'})" | |
echo XXX | |
done | |
fi | |
else | |
if [[ $hour -lt 10 ]];then | |
restic backup -q "$backup" --time "2017-0$months-$days 0$hour:00:00" 2>/dev/null & | |
((i++)) | |
#echo "2017-0$months-$days 0$hour:00:00" | |
while [[ -e /proc/$! ]]; do | |
echo XXX | |
echo $i | awk '{ printf "%.0f\n", $1*0.01119946242580356142905140553253 }' | |
echo "This will take a while! We're now @ $(ps aux | grep [r]estic| awk {'printf ("%s %s", $16, $17)'})" | |
echo XXX | |
done | |
else | |
restic backup -q "$backup" --time "2017-0$months-$days $hour:00:00" 2>/dev/null & | |
((i++)) | |
#echo "2017-0$months-$days $hour:00:00" | |
while [[ -e /proc/$! ]]; do | |
echo XXX | |
echo $i | awk '{ printf "%.0f\n", $1*0.01119946242580356142905140553253 }' | |
echo "This will take a while! We're now @ $(ps aux | grep [r]estic| awk {'printf ("%s %s", $16, $17)'})" | |
echo XXX | |
done | |
fi | |
fi | |
else | |
if [[ $days -lt 10 ]]; then | |
if [[ $hour -lt 10 ]];then | |
restic backup -q "$backup" --time "2017-$months-0$days 0$hour:00:00" 2>/dev/null & | |
((i++)) | |
#echo "2017-$months-0$days 0$hour:00:00" | |
while [[ -e /proc/$! ]]; do | |
echo XXX | |
echo $i | awk '{ printf "%.0f\n", $1*0.01119946242580356142905140553253 }' | |
echo "This will take a while! We're now @ $(ps aux | grep [r]estic| awk {'printf ("%s %s", $16, $17)'})" | |
echo XXX | |
done | |
else | |
restic backup -q "$backup" --time "2017-$months-0$days $hour:00:00" 2>/dev/null & | |
((i++)) | |
#echo "2017-$months-0$days $hour:00:00" | |
while [[ -e /proc/$! ]]; do | |
echo XXX | |
echo $i | awk '{ printf "%.0f\n", $1*0.01119946242580356142905140553253 }' | |
echo "This will take a while! We're now @ $(ps aux | grep [r]estic| awk {'printf ("%s %s", $16, $17)'})" | |
echo XXX | |
done | |
fi | |
else | |
if [[ $hour -lt 10 ]];then | |
restic backup -q "$backup" --time "2017-$months-$days 0$hour:00:00" 2>/dev/null & | |
((i++)) | |
#echo "2017-$months-$days 0$hour:00:00" | |
while [[ -e /proc/$! ]]; do | |
echo XXX | |
echo $i | awk '{ printf "%.0f\n", $1*0.01119946242580356142905140553253 }' | |
echo "This will take a while! We're now @ $(ps aux | grep [r]estic| awk {'printf ("%s %s", $16, $17)'})" | |
echo XXX | |
done | |
else | |
restic backup -q "$backup" --time "2017-$months-$days $hour:00:00" 2>/dev/null & | |
((i++)) | |
#echo "2017-$months-$days $hour:00:00" | |
while [[ -e /proc/$! ]]; do | |
echo XXX | |
echo $i | awk '{ printf "%.0f\n", $1*0.01119946242580356142905140553253 }' | |
echo "This will take a while! We're now @ $(ps aux | grep [r]estic| awk {'printf ("%s %s", $16, $17)'})" | |
echo XXX | |
done | |
fi | |
fi | |
fi | |
((hour++)) | |
done | |
((days++)) | |
done | |
((months++)) | |
done | whiptail --title 'Creating hourly snapshots for each day of the year...' --gauge "Please be patient..." 6 65 0 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment