-
Notifications
You must be signed in to change notification settings - Fork 2
/
backup.sh
executable file
·41 lines (35 loc) · 1.2 KB
/
backup.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
#!/bin/bash
cat <<"EOF"
____ _
| __ ) __ _ ___| | ___ _ _ __
| _ \ / _` |/ __| |/ / | | | '_ \
| |_) | (_| | (__| <| |_| | |_) |
|____/ \__,_|\___|_|\_\\__,_| .__/
|_|
EOF
source_folder="$HOME/dotfiles/"
destination_folder="$HOME/Downloads/archConfig/dotfiles"
sync_dotfiles() {
find "$source_folder" ! -path "*/.git/*" | while IFS= read -r src_item; do
relative_path="${src_item#$source_folder}"
dest_item="$destination_folder/$relative_path"
if [ -d "$src_item" ]; then
if [ ! -d "$dest_item" ] && [ "$(basename "$src_item")" != ".git" ]; then
echo "Adding missing directory: $relative_path"
mkdir -p "$dest_item"
fi
elif [ -f "$src_item" ]; then
if [ ! -f "$dest_item" ]; then
echo "Adding missing file: $relative_path"
cp "$src_item" "$dest_item"
else
if ! cmp -s "$src_item" "$dest_item"; then
echo "Replacing modified file: $relative_path"
cp "$src_item" "$dest_item"
fi
fi
fi
done
}
sync_dotfiles
echo "Backup completed."