#!/bin/bash # # sync-tpc # # Parameters BASENAME="`basename $0`" TPC="$1" DEST="/media/$1" MEDIA="$DEST/var/cache/$TPC/media" RSYNC="ionice -c 3 nice -n 19 rsync -av --delete --progress" # Syntax if [ -z "$TPC" ]; then echo "usage: $BASENAME " exit 1 elif [ ! -d "$DEST" ]; then echo "folder $DEST does not exist." exit 1 fi # Sudo if [ "$USER" != 'root' ]; then export SUDO="sudo" fi # Encrypted home $SUDO mkdir -p $DEST/mnt/crypt/home # Encrypted mountpoints for folder in /mnt/crypt/home/*; do $SUDO mkdir -p $DEST/$folder done # Sync files for folder in /home /var/cache/pbuilder /var/chroot /var/lib/wicd; do if [ -d "$folder" ] && [ ! -e "$DEST/$folder/.sync-tpc-ignore" ]; then $SUDO $RSYNC $folder/ $DEST/$folder/ fi done # Network config $SUDO cp -a /etc/network/interfaces $DEST/etc/network/interfaces $SUDO cp -a /etc/udev/rules.d/70-persistent-net.rules $DEST/etc/udev/rules.d/70-persistent-net.rules # Custom network config if [ -e '/etc/network/interfaces.d/' ]; then $SUDO $RSYNC /etc/network/interfaces.d/ $DEST/etc/network/interfaces.d/ fi # Wicd if [ -d "/etc/wicd" ]; then $SUDO mkdir -p $DEST/etc/wicd $SUDO cp -a /etc/wicd/manager-settings.conf $DEST/etc/wicd/manager-settings.conf $SUDO cp -a /etc/wicd/wireless-settings.conf $DEST/etc/wicd/wireless-settings.conf fi # Network Manager if [ -d "/etc/NetworkManager/system-connections" ]; then $SUDO mkdir -p $DEST/etc/NetworkManager/system-connections $SUDO rsync -av --delete /etc/NetworkManager/system-connections/ $DEST/etc/NetworkManager/system-connections/ fi # Ensure the media folder exist if [ ! -d "$MEDIA" ]; then $SUDO mkdir -p $MEDIA OWNER="$(stat -c %U /var/cache/`hostname -s`/media)" GROUP="$(stat -c %G /var/cache/`hostname -s`/media)" # With the right permissions $SUDO chown $OWNER:$GROUP $MEDIA fi # Guest images were previously synced using rsync #$SUDO $RSYNC /var/cache/virtualbox/ $DEST/var/cache/virtualbox/ #$SUDO $RSYNC /var/cache/qemu/ $DEST/var/cache/qemu/ #$SUDO $RSYNC /var/cache/vagrant/ $DEST/var/cache/vagrant/ # Sync qemu guest images if [ -d "/var/cache/qemu" ] && [ ! -e "$DEST/var/cache/qemu/.sync-tpc-ignore" ]; then hydractl sync-guestfs /var/cache/qemu $DEST/var/cache/qemu fi # Sync media remotes hydractl sync-media-remotes $MEDIA # Record log $SUDO mkdir -p $DEST/var/log/hydra echo "`date +%Y%m%d` $BASENAME with data from `cat /etc/hostname`" | $SUDO tee -a $DEST/var/log/hydra/sync-tpc > /dev/null