Skip to content

Instantly share code, notes, and snippets.

@DennisLfromGA
Last active May 12, 2020 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DennisLfromGA/e6b9bbc3512e751d6f87a99fd6d08550 to your computer and use it in GitHub Desktop.
Save DennisLfromGA/e6b9bbc3512e751d6f87a99fd6d08550 to your computer and use it in GitHub Desktop.
#!/bin/bash
## Backup script for use before powerwashing or recovery.
ANS=''
DAT="$(date +%m%d%Y)"
DIR="$HOME/Downloads/$DAT"
EXF='--exclude-tag-under=.EXCLUDE'
MOD='Eve'
NIX='/var/crouton/chroots/trusty/home/denny'
echo_e='/bin/echo -e'
xit=0
## ## BACKUP Procedure
## $ tar -caf $DIR/homefiles.$MOD-$(date +%m%d%Y-%H.%M).tar $EXF -C $HOME/ -T $HOME/.homefiles
## $ sudo tar -caf $DIR/usr.local.bin.$MOD-$(date +%m%d%Y-%H.%M).tar $EXF -C /usr/local bin/
## $ tar -caf $DIR/archive.$MOD-$(date +%m%d%Y-%H.%M).tar $EXF -C /var/crouton archive/
## $ tar -caf $DIR/nix.files.$MOD-$(date +%m%d%Y-%H.%M).tar $EXF -C $NIX/ -T $NIX/.homefiles
## $ tar -caf $DIR/cros-all.$MOD-$(date +%m%d%Y).tar.gz $DIR/*.$MOD-$(date +%m%d%Y*).tar
##
## ## RESTORE Procedure
## $ cd [$DIR]
## $ gzip -dk cros-files.$MOD-*.tar.gz
## $ tar -xaf homefiles.$MOD-*.tar -C $HOME/
## $ sudo tar -xaf usr.local.bin.$MOD-*.tar -C /usr/local/
## $ tar -xaf archive.$MOD-*.tar -C /var/crouton/
## $ tar -xaf nix.files.$MOD-$(date +%m%d%Y).tar -C [$NIX]/
mkdir $DIR || xit=1
touch $DIR/.EXCLUDE
if [ $xit -gt 1 ]; then echo "Exiting on error '$xit' ..."; exit $xit; fi
cd $DIR 2>/dev/null
echo "....................................................................................."
## BACKUPS ##
## $HOME files
echo -n "Perform backup of 'homefiles' (Y/n/q) ? " 1>&2
read ANS; if [ -z "${ANS}" ]; then ANS='y'; fi
case "${ANS}" in
[yY]*) echo "Tarring 'homefiles' ..."
tar -caf $DIR/homefiles.$MOD-$(date +%m%d%Y-%H.%M).tar $EXF -C $HOME/ -T $HOME/.homefiles 2>/dev/null || xit=2
if [ $xit -gt 1 ]; then echo "Exiting on error '$xit' ..."; exit $xit; fi
;;
[qQ]*) ${echo_e} "\nQuitting, as requested`...\n"
exit 0
;;
*) ${echo_e} "\nSkipping 'homefiles' backup`...\n"
;;
esac
ANS=''
## /usr/local/bin files
echo -n "Perform backup of '/usr/local/bin' (Y/n/q) ? " 1>&2
read ANS; if [ -z "${ANS}" ]; then ANS='y'; fi
case "${ANS}" in
[yY]*) echo "Tarring '/usr/local/bin/' ..."
sudo tar -caf $DIR/usr.local.bin.$MOD-$(date +%m%d%Y-%H.%M).tar $EXF -C /usr/local bin/ 2>/dev/null || xit=3
if [ $xit -gt 1 ]; then echo "Exiting on error '$xit' ..."; exit $xit; fi
;;
[qQ]*) ${echo_e} "\nQuitting, as requested`...\n"
exit 0
;;
*) ${echo_e} "\nSkipping '/usr/local/bin' backup`...\n"
;;
esac
ANS=''
## archive files
echo -n "Perform backup of 'crouton/archive' (Y/n/q) ? " 1>&2
read ANS; if [ -z "${ANS}" ]; then ANS='y'; fi
case "${ANS}" in
[yY]*) echo "Tarring 'crouton/archive' ..."
tar -caf $DIR/archive.$MOD-$(date +%m%d%Y-%H.%M).tar $EXF -C /var/crouton archive/ || xit=4
if [ $xit -gt 1 ]; then echo "Exiting on error '$xit' ..."; exit $xit; fi
;;
[qQ]*) ${echo_e} "\nQuitting, as requested`...\n"
exit 0
;;
*) ${echo_e} "\nSkipping 'crouton/archive' backup`...\n"
;;
esac
ANS=''
## nix files
echo -n "Perform backup of 'trusty nix' (Y/n/q) ? " 1>&2
read ANS; if [ -z "${ANS}" ]; then ANS='y'; fi
case "${ANS}" in
[yY]*) echo "Tarring 'trusty nix' ..."
tar -caf $DIR/nix.files.$MOD-$(date +%m%d%Y-%H.%M).tar $EXF -C $NIX/ -T $NIX/.homefiles 2>/dev/null || xit=5
if [ $xit -gt 1 ]; then echo "Exiting on error '$xit' ..."; exit $xit; fi
;;
[qQ]*) ${echo_e} "\nQuitting, as requested`...\n"
exit 0
;;
*) ${echo_e} "\nSkipping 'trusty nix' backup`...\n"
;;
esac
ANS=''
## add README file
echo "Copying 'README' ..."
cp $HOME/Downloads/README.$MOD $DIR || xit=6
if [ $xit -gt 1 ]; then echo "Exiting on error '$xit' ..."; exit $xit; fi
## gzip everything up
echo "Gunzipping 'tar files' ..."
sudo tar -caf $DIR/cros-all.$MOD-$(date +%m%d%Y).tar.gz -C $DIR *.tar README.$MOD || xit=7
if [ $xit -gt 1 ]; then echo "Exiting on error '$xit' ..."; exit $xit; fi
mv $DIR/*.tar $DIR/README.$MOD /tmp
echo "Done - xit is '$xit' ..."
ls -l $DIR
echo "....................................................................................."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment