Skip to content

Instantly share code, notes, and snippets.

@cyakimov
Forked from kennethso168/restic_backup.sh
Created November 30, 2021 00:07
Show Gist options
  • Save cyakimov/7a67b17500281da3d05a33c7861004c7 to your computer and use it in GitHub Desktop.
Save cyakimov/7a67b17500281da3d05a33c7861004c7 to your computer and use it in GitHub Desktop.
My Backup Solution
#!/bin/bash
# Location of your restic repo
export RESTIC_REPOSITORY=/run/media/kenneth/MyBook/restic
# Password of the restic repo
# Use a keyring to store the password so it isn't stored in plaintext on disk
# Install python-keyring (Arch) to use this command
export RESTIC_PASSWORD=`keyring get restic MyBook`
if ! restic snapshots
then
echo "Error accessing repo. Aborting"
exit 1
fi
# Define what directories/files to backup from a text file
restic backup --files-from /home/kenneth/bin/restic_dir/home.txt
# TODO this doesn't check the data
# A better way is to automate checking subset of data one at a time
read -p "Perform integrity check? (y/n) "
if [[ $REPLY = [yY] ]]
then
restic check
fi
# Sync the whole restic repo to a remote
# Adapt this to your rclone remote name
read -p "Sync repo to OneDrive? (y/n) "
if [[ $REPLY = [yY] ]]
then
rclone sync /run/media/kenneth/MyBook/restic onedrive:restic --verbose --checkers 20 --transfers 16
fi
# This works as restic can read from rclone remotes directly (by prepending "rclone:")
read -p "Perform integrity check for the repo on OneDrive? (y/n) "
if [[ $REPLY = [yY] ]]
then
restic -r rclone:onedrive:restic check
fi
#!/bin/bash
read -p 'Rotate snapshot with timeshift? (y/n): '
if [[ $REPLY = [yY] ]]
then
# TODO a better way is to detect the current number of snapshots first and delete if there is more than a number
# Since I always have a few manual snapshots present I don't bother doing it yet
sudo timeshift --delete --snapshot "$(sudo timeshift --list | grep '>.*O' | head -n 1 | awk '{print $3}')" --scripted
sudo timeshift --create --scripted
fi
read -p 'Do you want to see the status of mirrors? (y/n): '
[[ $REPLY = [yY] ]] && xdg-open repo.manjaro.org
read -p "Proceed with system update? (y/n): "
[[ $REPLY = [yY] ]] || exit 1
echo "Undergoing system update..."
sudo pacman -Syyu
# I'm using refind, but grub is also installed, which becomes the default after an update
# This command just switches the default bootloader back to refind
sudo refind-install
# TODO I know, pacaur is no longer maintained.
# Don't have time to choose an alternative yet.
echo "Showing list of updates for AUR packages"
pacaur -k
echo 'Update AUR packages that you wish by running "pacaur -u <package>"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment