-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup
executable file
·67 lines (54 loc) · 1.49 KB
/
backup
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
set -e
DOTFILES_BACKUP_DELETE_LOCAL=0
DOTFILES_BACKUP_DIR=".dotfiles.bak.$(date +'%Y%m%d-%H%M')"
function dotfiles_backup {
for file_name in \
".bash_aliases" \
".bash_functions" \
".bash_logout" \
".bash_profile" \
".bashrc" \
".dotfiles/.bashrc.env.local" \
".dotfiles/.bashrc.local" \
".gitconfig" \
".dotfiles/.gitconfig.local" \
".gitignore.global" \
".minttyrc" \
".vimrc" \
".xbindkeysrc" \
".Xmodmap"
do
if [ -f ~/${file_name} ] && [ ! -L ~/${file_name} ] ; then
dotfile_backup ${file_name}
fi
done
}
function dotfile_backup {
if [ -z "$DOTFILES_BACKUP_DIR" ]; then
echo "Undefined backup directory"
exit 1
fi
if [ ! -d ~/"${DOTFILES_BACKUP_DIR}" ]; then
mkdir -p ~/"${DOTFILES_BACKUP_DIR}"
fi
local file_name=$*
if [ -f ~/"${file_name}" ] && [ ! -L ~/"${file_name}" ] ; then
local dest_file_name; dest_file_name=$(basename "$file_name")
echo "Backing up ~/${DOTFILES_BACKUP_DIR}/${file_name}"
cp ~/"${file_name}" ~/"${DOTFILES_BACKUP_DIR}/${dest_file_name}"
fi
if [ -f ~/"${DOTFILES_BACKUP_DIR}/${file_name}" ] && [ "$DOTFILES_BACKUP_DELETE_LOCAL" = "1" ]; then
rm ~/"${file_name}"
fi
}
# Read command options
while getopts ":-:" opt; do
case "${OPTARG}" in
delete)
DOTFILES_BACKUP_DELETE_LOCAL=1
;;
esac
done
# Run
dotfiles_backup