backup (862B)
1 #!/bin/sh 2 3 DATESTAMP=$(date +%Y%m%d) 4 5 OPTS="cfJ" 6 EXT="xz" 7 8 INCLUDED_DIRS=".*(bin|Downloads|latex|git|services)$" 9 INCLUDED_FILES=".*\.(md|pdf|png|config|py)$" 10 EXCLUDED_DIRS="" 11 EXCLUDED_FILES="" 12 13 OLD=$(pwd) 14 INCLUDED=$(mktemp) 15 EXCLUDED=$(mktemp) 16 17 EXIT () { 18 rm $INCLUDED $EXCLUDED 19 cd $OLD 20 exit $1 21 } 22 23 cd $HOME 24 25 find . -maxdepth 1 -type d -regextype posix-egrep -regex $INCLUDED_DIRS -print >> $INCLUDED 26 find . -maxdepth 1 -type f -regextype posix-egrep -regex $INCLUDED_FILES -print >> $INCLUDED 27 28 for DIR in $EXCLUDED_DIRS; do 29 sed "/$DIR/d" -i $INCLUDED 30 done 31 32 for FILE in $EXCLUDED_FILES; do 33 sed "/$FILE/d" -i $INCLUDED 34 done 35 36 if [ ! "${INCLUDED:-x}" = "x" ]; then 37 tar cfJ "$HOME/backup-$DATESTAMP.tar.$EXT" -T $INCLUDED --backup=numbered 38 # TODO(mikolaj): encrypt and sign the resulting backup file 39 EXIT 0 40 else 41 echo "No files selected to back up!" 42 EXIT 1 43 fi