yadm-new/.bashrc.d/backup-func

176 lines
4.5 KiB
Text

function backup-firefox() {
local archive="$1"
local target="$2"
local hostname
local date
if [[ -z "$1" ]]; then
archive="$(grep -E '^ID=' /etc/os-release | cut -d'=' -f2)$(grep -E '^VERSION_ID=' /etc/os-release | cut -d'=' -f2)"
if [[ -z "$archive" ]]; then
archive="latest"
fi
fi
if [[ -z "$2" ]]; then
if [[ -d "/mnt/storage/psi-jack/Backups" ]]; then
target="/mnt/storage/psi-jack/Backups"
else
target="/home/psi-jack/Backups"
fi
fi
if [[ -f "/etc/hostname" ]]; then
hostname=$(< /etc/hostname)
else
hostname=$(hostname)
fi
date=$(date +"%Y-%m-%d")
mkdir -p "${target}/${archive}/${hostname}"
pushd "$HOME/.mozilla" &>/dev/null
tar -cvvf "${target}/${archive}/${hostname}/${hostname}-${date}_firefox.tar" firefox
zstd --rm -6 "${target}/${archive}/${hostname}/${hostname}-${date}_firefox.tar"
popd &>/dev/null
}
function backup-vivaldi() {
local archive="$1"
local target="$2"
local hostname
local date
if [[ -z "$1" ]]; then
archive="$(grep -E '^ID=' /etc/os-release | cut -d'=' -f2)$(grep -E '^VERSION_ID=' /etc/os-release | cut -d'=' -f2)"
if [[ -z "$archive" ]]; then
archive="latest"
fi
fi
if [[ -z "$2" ]]; then
if [[ -d "/mnt/storage/psi-jack/Backups" ]]; then
target="/mnt/storage/psi-jack/Backups"
else
target="/home/psi-jack/Backups"
fi
fi
if [[ -f "/etc/hostname" ]]; then
hostname=$(< /etc/hostname)
else
hostname=$(hostname)
fi
date=$(date +"%Y-%m-%d")
mkdir -p "${target}/${archive}/${hostname}"
pushd "$HOME" &>/dev/null
tar -cvvf "${target}/${archive}/${hostname}/${hostname}-${date}_vivaldi.tar" .config/vivaldi/Default
zstd --rm -6 "${target}/${archive}/${hostname}/${hostname}-${date}_vivaldi.tar"
popd &>/dev/null
}
function backup-home() {
local archive="$1"
local target="$2"
local hostname
local date
if [[ -z "$1" ]]; then
archive="$(grep -E '^ID=' /etc/os-release | cut -d'=' -f2)$(grep -E '^VERSION_ID=' /etc/os-release | cut -d'=' -f2)"
if [[ -z "$archive" ]]; then
archive="latest"
fi
fi
if [[ -z "$2" ]]; then
if [[ -d "/mnt/storage/psi-jack/Backups" ]]; then
target="/mnt/storage/psi-jack/Backups"
else
target="/home/psi-jack/Backups"
fi
fi
if [[ -f "/etc/hostname" ]]; then
hostname=$(< /etc/hostname)
else
hostname=$(hostname)
fi
date=$(date +"%Y-%m-%d")
mkdir -p "${target}/${archive}/${hostname}"
pushd /home &>/dev/null
tar \
--exclude=psi-jack/.local/share/Trash \
--exclude=psi-jack/.local/share/Steam \
--exclude=psi-jack/.local/share/bottles \
--exclude=psi-jack/.local/share/lutris \
--exclude=psi-jack/Audible \
--exclude=psi-jack/Downloads \
--exclude=psi-jack/Downloads.old \
--exclude=psi-jack/Games \
--exclude=psi-jack/"GOG Games" \
--exclude=psi-jack/ISO \
--exclude=psi-jack/Libation \
--exclude=psi-jack/Music \
--exclude=psi-jack/Vaults \
--exclude=psi-jack/tmp \
--exclude=psi-jack/.alchemynext/cache \
--exclude=psi-jack/.alchemynext/wine \
--exclude=psi-jack/.cache \
--exclude=psi-jack/.config/rambox \
--exclude=psi-jack/.firestorm_x64/cache \
--exclude=psi-jack/.thunderbird \
--exclude=psi-jack/.steam \
--exclude=psi-jack/.var \
--exclude=psi-jack/.vscode \
--exclude=psi-jack/.wine \
-cvvf "${target}/${archive}/${hostname}/${hostname}-${date}_home.tar" \
psi-jack
zstd --rm -6 "${target}/${archive}/${hostname}/${hostname}-${date}_home.tar"
popd &>/dev/null
}
function backup-system() {
local archive="$1"
local target="$2"
local hostname
local date
if [[ -z "$1" ]]; then
archive="$(grep -E '^ID=' /etc/os-release | cut -d'=' -f2)$(grep -E '^VERSION_ID=' /etc/os-release | cut -d'=' -f2)"
if [[ -z "$archive" ]]; then
archive="latest"
fi
fi
if [[ -z "$2" ]]; then
if [[ -d "/mnt/storage/psi-jack/Backups" ]]; then
target="/mnt/storage/psi-jack/Backups"
else
target="/home/psi-jack/Backups"
fi
fi
if [[ -f "/etc/hostname" ]]; then
hostname=$(< /etc/hostname)
else
hostname=$(hostname)
fi
date=$(date +"%Y-%m-%d")
mkdir -p "${target}/${archive}/${hostname}"
pushd / &>/dev/null
sudo tar -cvvf "${target}/${archive}/${hostname}/${hostname}-${date}_system.tar" etc root
sudo chown psi-jack: "${target}/${archive}/${hostname}/${hostname}-${date}_system.tar"
zstd --rm -6 "${target}/${archive}/${hostname}/${hostname}-${date}_system.tar"
popd &>/dev/null
}