Skip to content

Commit

Permalink
update bck script
Browse files Browse the repository at this point in the history
  • Loading branch information
pad92 committed May 11, 2023
1 parent c4f1883 commit aff6b4b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 31 deletions.
56 changes: 48 additions & 8 deletions bin/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,56 @@
. /etc/os-release

MNT_PTS='/mnt/pads918/home'
BACKUP_DIR="pascal@192.168.0.100:backup"
BACKUP_DIR="${MNT_PTS}/${USERNAME}/backup"
HOSTNAME="$(hostnamectl hostname)"

TIMESTAMP=$(date "+%Y%m%d-%H%M%S")
RSYNC_OPTS='--dry-run --archive --perms --xattrs --safe-links --no-specials --no-devices --info=progress2 --delete'
RSYNC_OPTS='--archive --perms --xattrs --safe-links --no-specials --no-devices --info=progress2 --delete --delete-excluded'
SUDO_OPTS='-E -s'
echo 'rsync /boot'
sudo ${SUDO_OPTS} rsync ${RSYNC_OPTS} /boot/ ${BACKUP_DIR}/${HOSTNAME}/boot/
echo 'rsync /etc'
sudo ${SUDO_OPTS} rsync ${RSYNC_OPTS} /etc/ ${BACKUP_DIR}/${HOSTNAME}/etc/
echo "rsync ${HOME}"
if [ ! -d "${BACKUP_DIR}/${HOSTNAME}${HOME}/" ]; then
echo "create ${BACKUP_DIR}/${HOSTNAME}${HOME}/"
sudo mkdir -p "${BACKUP_DIR}/${HOSTNAME}${HOME}/"
fi
PKGLIST_OLD="$(sudo ls -1 ${BACKUP_DIR}/${HOSTNAME}/pkglist-*.txt 2>/dev/null | tail -1)"
PKGLIST_CURRENT="${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}-${ID}.txt"

sudo ${SUDO_OPTS} rsync ${RSYNC_OPTS} --delete-excluded --exclude='Download/' --exclude='Cache/' --exclude-from=${HOME}/.dotfiles/dist/backup_excludes.txt ${HOME}/ "${BACKUP_DIR}/${HOSTNAME}${HOME}/"
[ -z "${ID_LIKE}" ] && ID_LIKE="${ID}"

case $ID_LIKE in
arch)
ORPHAN=$(pacman -Qtdq)

if [ -n "${ORPHAN}" ]; then
echo "Remove orphans"
yay -Rs $(pacman -Qtdq)
fi

yay -Scc --noconfirm

pacman -Qqe | awk '{print $1}' | sudo tee -a ${PKGLIST_CURRENT} 1>/dev/null

;;
debian)
sudo apt autoremove --purge
dpkg --get-selections '*' | sudo tee -a ${PKGLIST_CURRENT} 1>/dev/null

;;

*)
echo "unknown"
exit 1
;;
esac

if [ -s "${PKGLIST_OLD}" ]; then
diff -U 0 "${PKGLIST_OLD}" "${PKGLIST_CURRENT}" > "${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}.diff"
if [ -s "${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}.diff" ]; then
cat "${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}.diff"
else
rm -f "${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}.diff"
fi
fi

sudo rsync ${RSYNC_OPTS} ${HOME}/ ${BACKUP_DIR}/${HOSTNAME}${HOME}/ --exclude-from=- <<- EOF
$(cat ${HOME}/.no_backup.txt ${HOME}/.dotfiles/dist/backup_excludes.txt)
EOF
76 changes: 53 additions & 23 deletions dist/backup_excludes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#/.aMule
#/Scribus
#/VirtualBox*
#.local/share/gnome-boxes/images
#/Nextcloud
#_build
#
Expand All @@ -47,6 +48,7 @@
#
#/games
#.local/share/Steam
#.var/app/com.valvesoftware.Steam/.local/share/Steam
#.steam
#/Steam
#.minecraft
Expand All @@ -56,6 +58,7 @@
#
## Spotify
#.config/spotify/Users
#.var/app/com.spotify.Client/config/spotify/Users
#
## those folders contain only temporary Videos I want to watch
#/Videos
Expand All @@ -78,6 +81,9 @@
#
## Unlocked Plasma Vaults
#/Vaults
## Docker
#.docker/machine
#.local/share/containers

################################################
# These directories may definitely be excluded #
Expand All @@ -93,6 +99,8 @@
# Session-specific:
/.dbus
.cache
.var/app/*/cache
.var/app/*/.cache
/.Trash
.Trash-1*
.local/share/Trash
Expand Down Expand Up @@ -121,6 +129,7 @@

# Contains errors from the current graphical session
.xsession-errors
.xsession-errors.old
.wayland-errors

# Recently used files
Expand Down Expand Up @@ -154,6 +163,9 @@ Thumbs.db
.pulse-cookie
.esd_auth

# Lock / Pid files
.VeraCrypt-lock-*

#KDE specific:

# Recent documents on KDE
Expand Down Expand Up @@ -289,30 +301,31 @@ Thumbs.db
#Google Chrome:

.config/google-chrome/ShaderCache
.config/google-chrome/Default/Local Storage
.config/google-chrome/Default/Session Storage
.config/google-chrome/Default/Application Cache
.config/google-chrome/Default/History Index *
.config/google-chrome/Default/Service Worker/CacheStorage
.config/google-chrome/*/Local Storage
.config/google-chrome/*/Session Storage
.config/google-chrome/*/Application Cache
.config/google-chrome/*/History Index *
.config/google-chrome/*/Service Worker/CacheStorage

#Chromium:

.config/chromium/Default/Local Storage
.config/chromium/Default/Session Storage
.config/chromium/Default/Application Cache
.config/chromium/Default/History Index *
.config/chromium/*/Local Storage
.config/chromium/*/Session Storage
.config/chromium/*/Service Worker/CacheStorage
.config/chromium/*/Application Cache
.config/chromium/*/History Index *
/snap/chromium/common/.cache
/snap/chromium/*/.config/chromium/Default/Service Worker/CacheStorage
/snap/chromium/*/.config/chromium/*/Service Worker/CacheStorage
/snap/chromium/*/.local/share/

#Riot
/snap/riot-web/

#Brave
.config/BraveSoftware/Brave-Browser/Default/Feature Engagement Tracker/
.config/BraveSoftware/Brave-Browser/Default/Local Storage/
.config/BraveSoftware/Brave-Browser/Default/Service Worker/CacheStorage/
.config/BraveSoftware/Brave-Browser/Default/Session Storage/
.config/BraveSoftware/Brave-Browser/*/Feature Engagement Tracker/
.config/BraveSoftware/Brave-Browser/*/Local Storage/
.config/BraveSoftware/Brave-Browser/*/Service Worker/CacheStorage/
.config/BraveSoftware/Brave-Browser/*/Session Storage/
.config/BraveSoftware/Brave-Browser/Safe Browsing/
.config/BraveSoftware/Brave-Browser/ShaderCache/

Expand Down Expand Up @@ -360,18 +373,12 @@ nohup.out
# VS Code
.vscode-oss/extensions/*
.vscode/extensions/*
.config/Code - OSS/blob_storage/
.config/Code - OSS/GPUCache/
.config/Code - OSS/logs/
.config/Code/blob_storage/
.config/Code/GPUCache/
.config/Code/logs/
.config/Code/CachedData/*

# MS Teams
.config/Microsoft/Microsoft Teams/Application Cache
.config/Microsoft/Microsoft Teams/Cache
.config/Microsoft/Microsoft Teams/Code Cache
.config/Microsoft/Microsoft Teams/GPUCache
# VS Codium
.config/VSCodium/CachedExtensionVSIXs

# VirtualBox
.config/VirtualBox/VBoxSVC.log*
Expand Down Expand Up @@ -401,3 +408,26 @@ go/pkg/mod/cache

# Geany IDE - socket file
.config/geany/geany_socket_*

# LBRY
.config/lbry
.local/share/lbry/lbrynet

# Electron Apps
.config/**/blob_storage
.config/**/Application Cache
.config/**/Cache
.config/**/CachedData
.config/**/Code Cache
.config/**/GPUCache
.config/**/Service Worker/CacheStorage
.var/app/**/blob_storage
.var/app/**/Application Cache
.var/app/**/Cache
.var/app/**/CachedData
.var/app/**/Code Cache
.var/app/**/GPUCache
.var/app/**/Service Worker/CacheStorage

# SC-Controller - socket file
.config/scc/daemon.socket

0 comments on commit aff6b4b

Please sign in to comment.