-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_files
executable file
·54 lines (43 loc) · 1.54 KB
/
sync_files
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
#!/bin/bash
#------------------------------------------------------------------------------#
#Title :sync_files
#Author :Ivan Batistic
#Date :01/2023
#Version :0.1
#Bash_version :5.1.16(1)-release
#Description :Sync two folders using rsync
#------------------------------------------------------------------------------#
if [[ ( $# -eq 0 ) || ( $1 == "--help" ) || ( $1 == "-h" ) ]] ; then
echo "Configured rsync function to sync files"
echo " "
echo "Options used: -rtpv --progress --delete --modify-window=1 -lHs"
echo " "
echo "Mandatory arguments (can be relative path): "
echo "PATH_FROM: sourceDir/"
echo "PATH_TO: targetDir/"
echo " "
echo "Example:"
echo "rsync -r -t -p -v --progress --delete --modify-window=1 -l -H -s sourceDir/ targetDir/"
exit 1
fi
if [[ $# -ne 2 ]]; then
echo "2 argument required, $# provided" >&2
exit 2
fi
#grabs last passed argument..
for last; do true; done
printf "\n"
echo "Source folder: ${@:1:$(($#-1))}"
echo "Target folder: $last"
printf "\n"
while true; do
rsync -n -r -t -p -v --progress --delete --modify-window=1 -l -H -s ${@:1:$(($#-1))} $last
read -p "Do you want to continue? (y/n) " yn
case $yn in
[yY] ) rsync -r -t -p -v --progress --delete --modify-window=1 -l -H -s ${@:1:$(($#-1))} $last
break;;
[nN] ) break;;
* ) echo invalid response;;
esac
done
#------------------------------------------------------------------------------#