-
Notifications
You must be signed in to change notification settings - Fork 2
/
fileBackup.sh
executable file
·46 lines (42 loc) · 1.47 KB
/
fileBackup.sh
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
#!/usr/bin/env bash
## search sub-folder paths and create symlinks of un-ignored files
## example: ln -s $HOME/dotfiles/.bashrc $HOME/.bashrc
# The following script assumes filenames do not contain
# control characters and dont contain leading dashes(-).
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
IFS="$(printf '\n\t')" # change IFS to just newline and tab
FAIL="TRUE"
cd "${HOME}/dotfiles"
dotfilePaths="$(fd -uu --type f --ignore-file "$HOME/dotfiles/ignorefiles" --ignore-file "$HOME/dotfiles/.gitignore")"
DATETIME=$(date +"%Y%m%d_%H%M%S")
BACK_FOLDER="${HOME}/back/${DATETIME}_backconfig/"
#mkdir -p "$BACK_FOLDER"
while IFS= read -r dfPath; do
printf '%-40s' "$dfPath"
#dfabsPath="${HOME}/dotfiles/${dfPath}"
backupAbsPath="${BACK_FOLDER}/${dfPath}"
backupFolderPath=$(dirname "$backupAbsPath")
sysAbsPath="${HOME}/${dfPath}"
if test -e "$sysAbsPath"; then
if ! test -L "$sysAbsPath"; then
if test -f "$sysAbsPath"; then #regular file?
mkdir -p "$backupFolderPath"
cp "$sysAbsPath" "$backupAbsPath"
printf '%-20s' "did backup"
FAIL="FALSE"
else
printf '%-20s' "no symlink or regular file"
fi
else
printf '%-20s' "is symlink"
fi
else
printf '%-20s' "found no file"
fi
echo -en "\n"
done <<<"$dotfilePaths"
if test "$FAIL" = "FALSE"; then
echo "backup created at ${BACK_FOLDER}"
fi