backups! initial version
parent
f103662bb5
commit
ad9f9ac72d
|
@ -0,0 +1,3 @@
|
|||
.env
|
||||
.repo-name
|
||||
.repo-pass
|
|
@ -0,0 +1,8 @@
|
|||
You've run across the directory where I set up everything relating to how I do personal backups. I should/ will/ do test, but if you see something wrong/ questionable, please let me know, thanks :)
|
||||
|
||||
Let's make sure we have these installed:
|
||||
|
||||
- Bash
|
||||
- Restic
|
||||
- msmtp set up
|
||||
- credentials set up w/ pash
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
$HOME/.Trash
|
||||
$HOME/.cache
|
||||
$HOME/.cargo
|
||||
$HOME/.config/google-chrome
|
||||
$HOME/.esmtp_queue
|
||||
$HOME/.java
|
||||
$HOME/.local/bin
|
||||
$HOME/.local/lib
|
||||
$HOME/.mozilla/firefox/*/storage/default/*/cache
|
||||
$HOME/.npm
|
||||
$HOME/.rustup
|
||||
$HOME/.steam
|
||||
$HOME/.steampath
|
||||
$HOME/.steampid
|
||||
$HOME/.subversion
|
||||
$HOME/.thunderbird/*/ImapMail
|
||||
$HOME/.thunderbird/*/Mail
|
||||
$HOME/.var/app/*/cache # Flatpak
|
||||
|
||||
$HOME/Downloads/nobkup
|
||||
$HOME/Music
|
||||
$HOME/tmp
|
||||
$HOME/Videos # temporary until i get it cleared up
|
||||
|
||||
$HOME/ghq # consider removing
|
||||
$HOME/ghq/**/node_modules
|
||||
|
||||
$HOME/.restore-info/tmp
|
||||
|
||||
# Nix
|
||||
$HOME/.nix-profile
|
||||
$HOME/.nix-defexpr
|
||||
|
||||
# Nextcloud
|
||||
.owncloudsync.log
|
||||
.sync_*
|
||||
.sync-exclude.lst
|
||||
|
||||
*.part
|
||||
.DS_Store
|
||||
.TemporaryItems
|
||||
.Trash-1000
|
||||
.Trashes
|
||||
._*
|
||||
__pycache__
|
|
@ -0,0 +1,97 @@
|
|||
#!/usr/bin/env bash
|
||||
# set -euo pipefail
|
||||
|
||||
mkdir -p ~/.restore-info/tmp
|
||||
chmod 700 ~/.restore-info
|
||||
|
||||
# ./restic -r s3:https://<WASABI-SERVICE-URL>/<WASABI-BUCKET-NAME> init
|
||||
export AWS_ACCESS_KEY_ID=$(pash show personal-backups/aws-key-id)
|
||||
export AWS_SECRET_ACCESS_KEY=$(pash show personal-backups/aws-access-key)
|
||||
|
||||
repo=$(cat ~/.dotfiles/.restic/.repo-name)
|
||||
script_started=$(date +%Y-%M-%d_%k%M%S)
|
||||
|
||||
# $RESTIC_PASSWORD_FILE or $RESTIC_PASSWORD_COMMAND
|
||||
if [[ -f "$HOME/.dotfiles/.restic/.repo-pass" ]]; then
|
||||
export RESTIC_PASSWORD_FILE="$HOME/.dotfiles/.restic/.repo-pass"
|
||||
else
|
||||
export RESTIC_PASSWORD_COMMAND="pash show personal-backups/repo-pass"
|
||||
fi
|
||||
|
||||
# set email vars here
|
||||
[ -f ~/.dotfiles/.restic/.env ] && source ~/.dotfiles/.restic/.env
|
||||
|
||||
# Check internet connectivity
|
||||
echo "checking internet connectivity, pinging google.com"
|
||||
ping -c 1 google.com
|
||||
internet_check="$?"
|
||||
if [[ $internet_check != 0 ]]; then
|
||||
echo "You may not be connected to the internet"
|
||||
notify-send -u critical "The backup was unable to run:" "you are not connected to the internet"
|
||||
zenity --error --text "The backup was unable to run: you are not connected to the internet"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if metered
|
||||
# https://github.com/erikw/restic-systemd-automatic-backup
|
||||
# http://opensource.org/licenses/BSD-3-Clause
|
||||
systemctl is-active dbus.service >/dev/null 2>&1 || exit 0
|
||||
systemctl is-active NetworkManager.service >/dev/null 2>&1 || exit 0
|
||||
|
||||
metered_status=$(dbus-send --system --print-reply=literal \
|
||||
--system --dest=org.freedesktop.NetworkManager \
|
||||
/org/freedesktop/NetworkManager \
|
||||
org.freedesktop.DBus.Properties.Get \
|
||||
string:org.freedesktop.NetworkManager string:Metered \
|
||||
| grep -o ".$")
|
||||
|
||||
if [[ $metered_status =~ (1|3) ]]; then
|
||||
echo Current connection is metered
|
||||
notify-send -u critical "The backup was unable to run:" "your internet connection is metered"
|
||||
zenity --error --text "The backup was unable to run: your internet connection is metered"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
backup)
|
||||
cd ~ || exit 1
|
||||
|
||||
echo "exporting list of packages"
|
||||
rm ~/.restore-info/packages-* # clear existing
|
||||
# https://unix.stackexchange.com/questions/82880/how-to-replicate-installed-package-selection-from-one-fedora-instance-to-another
|
||||
# install w/ < $file xargs dnf -y install
|
||||
dnf repoquery --qf '%{name}' --userinstalled \
|
||||
| grep -v -- '-debuginfo$' \
|
||||
| grep -v '^\(kernel-modules\|kernel\|kernel-core\|kernel-devel\)$' \
|
||||
> ~/.restore-info/packages-${script_started}.txt
|
||||
|
||||
echo "exporting dnf repos list"
|
||||
rm ~/.restore-info/dnfrepos-* # clear existing
|
||||
dnf repolist enabled > ~/.restore-info/dnfrepos-${script_started}.txt
|
||||
|
||||
echo "starting backup"
|
||||
restic backup -r "$repo" \
|
||||
--one-file-system \
|
||||
--exclude-caches --exclude-file ~/.dotfiles/.restic/ignore.txt \
|
||||
--exclude-if-present .exclude_from_backup \
|
||||
~ -v > ~/.restore-info/tmp/backup-log-${script_started}.txt
|
||||
|
||||
restic_exit_code="$?"
|
||||
backup_stopped=$(date +%k%M%S)
|
||||
|
||||
cat <<EOMAIL | msmtp --read-envelope-from $BACKUP_EMAIL_TO
|
||||
To: $BACKUP_EMAIL_TO
|
||||
From: $BACKUP_EMAIL_FROM
|
||||
Subject: Backup report $script_started exiting $restic_exit_code
|
||||
|
||||
Stopped $backup_stopped
|
||||
|
||||
$(cat ~/.restore-info/tmp/backup-log-${script_started}.txt)
|
||||
EOMAIL
|
||||
;;
|
||||
prune)
|
||||
echo "not implemented yet" ;;
|
||||
exec)
|
||||
shift
|
||||
restic -r "$repo" "$@" ;;
|
||||
esac
|
Loading…
Reference in New Issue