Skip to content

Instantly share code, notes, and snippets.

@shawnsi
Created November 20, 2014 17:18
Show Gist options
  • Save shawnsi/7f3c7e8173d1ff069528 to your computer and use it in GitHub Desktop.
Save shawnsi/7f3c7e8173d1ff069528 to your computer and use it in GitHub Desktop.
Backups to supplement Pacman based restores
#!/bin/bash
#
# Creates a tarsnap backup of all files we can't reasonably expect to get back
# from pacman. Files matching these conditions are included:
#
# 1. located in /etc and not owned by any package
# 2. owned by a package and modified since installation
# Create temporary space
INCLUDES=$(mktemp)
ROOT=$(mktemp -d /dev/shm/root.XXXXXXXX)
echo "Building package list..."
# Files in /etc not owned by any package
find /etc -type f -print0 \
| xargs -0 pacman -Qo 2>&1 \
| awk '/^error:/ { print $5 }' \
>> $INCLUDES
# Files modified since installation
pacman -Qkk 2>&1 \
| awk '/Size mismatch/ { print $3 }' \
>> $INCLUDES
echo "Creating temporary filesystem..."
# Build dummy root
rsync -av --files-from $INCLUDES / $ROOT/
echo "Backing up temporary filesystem..."
# Backup dummy root
tarsnap -C $ROOT/ -cf pacdiff.$(date +%F) .
# Cleanup temporary space
rm -r $INCLUDES $ROOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment