Initial Commit

This commit is contained in:
Tyler Mayoff 2024-09-30 18:06:03 -04:00
commit e726aebd5b
22 changed files with 1098 additions and 0 deletions

View file

@ -0,0 +1,41 @@
#!/bin/env fish
set current_date $(date +%Y-%m-%d)
set log_dir "$XDG_STATE_HOME/logs/backups"
set log_file "$log_dir/backup_$current_date.log"
set last $(restic snapshots | tail -3 | head -1 | awk '{print $2}')
if test $status != 0
echo "can't find last snapshot" | tee -a $log_file
notify-send -a "backup" "Failed to get last snapshot for backups" -u critical
exit $status
end
function exit_handler
# Restore std...
# exec 2>&4 1>&3
end
# Setup logging
mkdir -p $log_dir || true
trap exit_handler 0 1 2 3
printf "Current date: %s. Last snapshot: %s\n" $current_date $last | tee -a $log_file
if test "$last" != "$current_date"
set not_id $(notify-send -a "backup" "Daily backup $current_date started." -p)
restic backup -v "$HOME" --exclude-file "$XDG_CONFIG_HOME/restic/ignore" | tee -a $log_file
if test $status != 0
echo "Backup failed." | tee -a $log_file
notify-send -a "backup" "Backup $current_date failed!" -u critical -r $not_id
exit $status
end
printf "Backup success\n." | tee -a $log_file
notify-send -a "backup" "Daily backup $current_date succeeded." -r $not_id
else
printf "No backup needed" | tee -a $log_file
end

View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
echo "Cleaning remote branches"
git remote prune origin
echo "Cleaning local branches"
git for-each-ref --format '%(refname:short)' refs/heads | grep -v master | xargs git branch -D

View file

@ -0,0 +1,5 @@
#!/bin/bash
restic backup "$HOME" --exclude-file "$XDG_CONFIG_HOME"/restic/ignore --exclude-caches
restic unlock
restic forget --keep-daily 7 --keep-weekly 4 --prune

View file

@ -0,0 +1,4 @@
#!/bin/bash
restic snapshots | tail -3 | head -1 | awk '{print "Last backup: " $2 " " $3}'
restic check

View file

@ -0,0 +1,10 @@
#!/usr/bin/env fish
yadm pull
pushd $HOME/.local/share/yadm/repo.git
git-forgit add
yadm commit
popd
yadm push