Last active
February 1, 2019 19:18
-
-
Save samiemad/e30f55e4583a6bf264511ffcac8a2685 to your computer and use it in GitHub Desktop.
This file contains 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
.gvfs | |
.mozilla | |
.gradle/wrapper | |
.gradle/caches | |
.gradle/daemon | |
.gradle/native | |
.local/share/Trash | |
.local/share/Steam | |
cache | |
caches | |
.cache | |
Cache | |
build | |
target | |
out |
This file contains 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 | |
# fail on any error: | |
set -e | |
function doBackup { | |
# Get the included folders from arg array: | |
local -n inc=$1 | |
# get the output file from args: | |
out=$2 | |
# create the out dir if not exists | |
mkdir -p "${out%/*}" | |
echo "Backing up folders (${inc[@]}) to: $out ..." | |
printf "> Estimating size..." | |
SIZE=$(tar -c --one-file-system -C / \ | |
--exclude-backups \ | |
--exclude-caches \ | |
--exclude-from="$BACKUP_DIR/backup-excludes" \ | |
--exclude-tag='.nobackup' \ | |
--exclude-vcs-ignores \ | |
${inc[@]} \ | |
| wc -c) | |
printf "\rEstimated size of backup: `numfmt --to=iec $SIZE`\n" | |
SIZEARG="-s $SIZE" | |
tar -cpf - --one-file-system -C / \ | |
--exclude-backups \ | |
--exclude-caches \ | |
--exclude-from="$BACKUP_DIR/backup-excludes" \ | |
--exclude-tag='.nobackup' \ | |
--exclude-vcs-ignores \ | |
${inc[@]} \ | |
| pv $SIZEARG \ | |
| pigz > "$out" | |
echo "Compressed size: `du -h "$out"`" | |
echo "Done." | |
} | |
# Get the backup folder location: | |
BACKUP_DIR="$( cd $( dirname "${BASH_SOURCE[0]}" ) > /dev/null && pwd )" | |
# Get the date: | |
DATE=$(date --iso-8601=seconds) | |
if [[ $1 == "test" ]]; then | |
INC=(etc root) | |
doBackup INC "${BACKUP_DIR}/test backups/$DATE-test.tar.gz" | |
exit | |
fi | |
INC=(home opt etc root) | |
doBackup INC "${BACKUP_DIR}/manual-backups/$DATE-files.tar.gz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment