-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.sh
More file actions
executable file
·47 lines (24 loc) · 985 Bytes
/
backup.sh
File metadata and controls
executable file
·47 lines (24 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
VERSION=2
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
pushd "$SCRIPT_DIR"
# folder to backup
FOLDER=${FOLDER:-"$(basename $(pwd))"}
# folder to put backups
mkdir -p "_backups"
TIMESTAMP=$(date +%s)
FILEDATETIME=$(date +%Y-%m-%d_%H-%M-%S)
FILENAME_BACKUP="$FOLDER-$FILEDATETIME"
if git log -1 --pretty=%B; then
# has a git message in repo
git_last_commit_message_sanitized="$(git log -1 --pretty=%B | head -n1 | sed -E 's/[^a-zA-Z0-9_-]+/_/g; s/_+/_/g; s/_-_/_/g; s/^-|-$//g' | tr '[:upper:]' '[:lower:]' | cut -c1-128)"
FILENAME_BACKUP="$FOLDER-$FILEDATETIME-$git_last_commit_message_sanitized"
else
# no message
FILENAME_BACKUP="$FOLDER-$FILEDATETIME"
fi
#tar --exclude="./backups/*.gz" -zcvf "./backups/$FILENAME_BACKUP.tar.gz" "../$FOLDER"
tar --exclude="*.bak.tar.gz" -zcvf "./_backups/$FILENAME_BACKUP.bak.tar.gz" "../$FOLDER"
popd
# EXTRACT WHILE PRESERVING SYMLINKS
# tar -xhzvf ARCHIVE.tar.gz