Files
dotfiles/local/bin/x-backup-folder.sh
Ismo Vuorinen bb3f4a8f6c Many updates and improvements
- yamllint
- shfmt config
- fix Go bin path
- fix git credentials config
- add nvm default packages
- updated Brewfile
2023-03-28 15:27:44 +03:00

26 lines
494 B
Bash
Executable File

#!/usr/bin/env bash
DIRECTORY=$1
FILENAME=$2
if [ -z "${DIRECTORY}" ]; then
echo "DIRECTORY (first argument) is missing"
echo "Usage: $0 folder_to_backup"
exit
fi
if [ -z "${FILENAME}" ]; then
FILENAME=$DIRECTORY
fi
FILENAME=${FILENAME} \
| tr '/' _ \
| iconv -t ascii//TRANSLIT \
| sed -r s/[^a-zA-Z0-9]+/_/g \
| sed -r s/^_+\|-+$//g
TIMESTAMP=$(date "+%Y%m%d_%H%M%S")
FILENAME_TIMESTAMP="${FILENAME}_${TIMESTAMP}"
tar cvzf "${FILENAME_TIMESTAMP}.tar.gz" "${DIRECTORY}/"