Skip to content

Instantly share code, notes, and snippets.

@toke
Last active March 13, 2017 09:29
Show Gist options
  • Save toke/b36b7e3e58f5a8ef758cf62e2cd166a9 to your computer and use it in GitHub Desktop.
Save toke/b36b7e3e58f5a8ef758cf62e2cd166a9 to your computer and use it in GitHub Desktop.
Pacman package database backup script. I use this on my laptop. Combined with ac-check.bash
#!/usr/bin/env bash
set -e
OUTDIR="${HOME}/backup/pacman/$(hostname --short)"
function usage() {
cat << EOF
$0 - backup pacman package database
USAGE:
-h|--help help
--outdir=PATH Override output directory (default: "${OUTDIR}")
EOF
}
### Main package information backup function
function pkgbackup () {
if [[ ! -e "${OUTDIR}}" ]] ; then
mkdir -p "${OUTDIR}"
fi
(nice /usr/bin/pacman -Qqe | nice grep -vx "$(/usr/bin/pacman -Qqm)" > "${OUTDIR}/pacman-list-main")
(nice /usr/bin/pacman -Qqem > "${OUTDIR}/pacman-list-other")
(nice /usr/bin/tar -cjf "${OUTDIR}/pacman-database-local.tar.bz2" -C / "var/lib/pacman/local")
exit 0
}
### Command line processing
for i in "$@"
do
case $i in
--outdir=*)
OUTDIR="${i#*=}"
shift # past argument=value
;;
-h|--help)
shift
usage
exit 0
;;
*)
echo "Unknown Option ${i}"
echo "Use $0 -h for usage"
exit 2
# unknown option
;;
esac
done
### Run default commands
pkgbackup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment