Skip to content

Instantly share code, notes, and snippets.

@u8sand
Last active March 5, 2022 23:36
Show Gist options
  • Save u8sand/9ea08eea61f12948410db26549c0a022 to your computer and use it in GitHub Desktop.
Save u8sand/9ea08eea61f12948410db26549c0a022 to your computer and use it in GitHub Desktop.
My ArchLinux system backup script; pacman tricks for system files, whitelisting for everything else. Paired with git for config git-lfs for files.
#!/bin/bash
wd=$(pwd)
#remote=root@host
run() {
local ret
if [ $remote ]; then
ssh $remote "$@" >&1;
else
bash -c "$@" >&1;
fi
}
lost_files=$(run 'lostfiles relaxed | grep -e"^\\/etc"')
pacman_files=$(run 'pacman -Qii | awk "/^MODIFIED/{print \$2}"')
all_files=$(echo ${lost_files} ${pacman_files} $(cat "$wd/whitelist") | sort | uniq)
if [ $remote ]; then
files=()
for f in $all_files; do
files+=($remote:$f);
done
export all_files=${files[@]}
fi
mkdir -p "$wd/pacman"
run 'pacman -Qenq' > "$wd/pacman/archpacks.txt"
run 'pacman -Qdnq' > "$wd/pacman/archdeps.txt"
run 'pacman -Qemq' > "$wd/pacman/aurpacks.txt"
run 'pacman -Qdmq' > "$wd/pacman/aurdeps.txt"
rsync \
--acls \
--archive \
--backup \
--backup-dir="$wd/backup/$(date +'%Y-%m-%d')" \
--compress \
--delete \
--delete-excluded \
--exclude-from="$wd/blacklist" \
--executability \
--fuzzy \
--include-from="$wd/whitelist" \
--progress \
--relative \
--verbose \
--xattrs \
$all_files \
"$wd/root/"
setfacl \
--recursive \
--modify 'u:u8sand:r-x' \
"$wd/"
/etc/passwd
/etc/passwd-
/etc/passwd.OLD
/etc/shadow
/etc/shadow-
/etc/shadow.OLD
/home/u8sand/.config/Atom/
/home/u8sand/.config/bakamplayer.ini
/home/u8sand/.config/gtk-3.0/settings.ini
/home/u8sand/.config/i3/
/home/u8sand/.config/sublime-text-3/
/home/u8sand/.config/Trolltech.conf
/home/u8sand/.config/xfce4/
/home/u8sand/.conkyrc
/home/u8sand/.gitconfig
/home/u8sand/.gtkrc-2.0
/home/u8sand/.ipython/profile_default/startup/
/home/u8sand/.local/bin/
/home/u8sand/.local/share/nemo/
/home/u8sand/.profile
/home/u8sand/.rclone.conf
/home/u8sand/.unison/
/home/u8sand/.vimrc
/home/u8sand/.xinitrc
/home/u8sand/.xserverrc
/home/u8sand/.zprofile
/home/u8sand/.zshrc
/home/u8sand/Templates/
@u8sand
Copy link
Author

u8sand commented Jan 16, 2018

For a better, more generic and extensible, backup script, see my new repo: https://github.com/u8sand/backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment