Skip to content

Instantly share code, notes, and snippets.

@mtarbit
Last active December 10, 2015 21:48
Show Gist options
  • Save mtarbit/4497947 to your computer and use it in GitHub Desktop.
Save mtarbit/4497947 to your computer and use it in GitHub Desktop.
Ubuntu backup script
#!/bin/bash
curr_date="$(date +%Y%m%d)"
base_path="/mnt/Elements/backup.$curr_date"
tgz_path="$base_path.tgz"
out_path="$base_path.out.log"
err_path="$base_path.err.log"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root." 1>&2
exit 1
fi
echo "Backing up system in $tgz_path"
echo "Output redirected to $out_path"
echo "Errors redirected to $err_path"
nohup tar -cvpzf \
"$tgz_path" \
--one-file-system \
--exclude=/dev \
--exclude=/home/*/.gvfs \
--exclude=/lost+found \
--exclude=/proc \
--exclude=/sys \
--exclude=/var/run \
/ 1> "$out_path" 2> "$err_path" &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment