Last active
April 21, 2024 08:07
-
-
Save evrardjp/bf15d4e73c4aa1a28097c6de6faab828 to your computer and use it in GitHub Desktop.
Backup Arch linux files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
MACHINE=$(cat /etc/hostname) | |
#DATE=$(date -Iminutes) #FOR MORE DETAILS | |
DATE=$(date -I) #JUST THE DATE | |
BACKUP_PATH=/root/backup-$MACHINE-$DATE | |
mkdir -p ${BACKUP_PATH} | |
function copy_file { | |
echo "Copying $1" | |
rsync --mkpath -a $i $BACKUP_PATH$i | |
} | |
function generate_log { | |
echo "Generating the list of manually edited files under pacman purfew" | |
echo "#pacman -Qii | awk '/\[modified\]/ {print \$(NF - 1)}'" > $BACKUP_PATH/LOG | |
pacman -Qii | awk '/\[modified\]/ {print $(NF - 1)}' >> $BACKUP_PATH/LOG | |
echo "Generating the list of files not seen by pacman" | |
echo "#find /etc /usr /opt | LC_ALL=C.UTF-8 pacman -Qqo - 2>&1 >&- >/dev/null | cut -d ' ' -f 5- | grep -v -e /usr/lib/module -e /etc/ssl/certs -e /etc/pacman.d/gnupg/ -e pacnew -e /etc/ca-certificates/extracted/ -e hwdb.bin" >> $BACKUP_PATH/LOG | |
find /etc /usr /opt | LC_ALL=C.UTF-8 pacman -Qqo - 2>&1 >&- >/dev/null | cut -d ' ' -f 5- | grep -v -e /usr/lib/module -e /etc/ssl/certs -e /etc/pacman.d/gnupg/ -e pacnew -e /etc/ca-certificates/extracted/ -e hwdb.bin >> $BACKUP_PATH/LOG | |
} | |
function generate_pkg_list { | |
echo "List of explicitly installed packages and their version" | |
pacman -Qe > $BACKUP_PATH/pacman-Qe.log | |
} | |
generate_log | |
for i in $(grep -v -e '^$' -e '^#' $BACKUP_PATH/LOG); do copy_file $i; done | |
generate_pkg_list | |
echo "Also copying gathering file script, just in case you wonder how these files were created" | |
rsync --mkpath -a "${BASH_SOURCE[0]}" "$BACKUP_PATH/${BASH_SOURCE[0]}" | |
echo "You can now rsync $BACKUP_PATH to target machine" | |
echo "Example: rsync --mkpath -a /root/backup-server02-2024-04-21 user@host:~/backups/ #BE CAREFUL ABOUT THE SLASHES." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment