-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
executable file
·53 lines (40 loc) · 1.4 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
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
utilities=('yad' '7z')
for utility in ${utilities[@]}; do
if ! command -v "$utility" 2>&1 >/dev/null; then
kdialog --title "$utility" --icon "error" --passivepopup "Not found" 3
exit 1
fi
done
oldIFS="$IFS"
IFS=$';'
read -r -a array <<< "$1"
# IFS="$oldIFS"
firstFile=${array[0]}
path=${firstFile%/*}
sufix=`date +%Y-%m-%d_%H-%M-%S`
parameters=`yad --width=300 --borders=20 --title="Add Time Stamp to file name" \
--form --separator="," --item-separator="|" \
--field="Sufix" --field="Method:CB" --field="Dir to save:DIR" \
"_$sufix" 'copy|move|zip|7z' "$path"`
exit_status=$?; if [ $exit_status != 0 ]; then exit; fi
sufix=$( echo $parameters | awk -F ',' '{print $1}')
method=$( echo $parameters | awk -F ',' '{print $2}')
dir=$( echo $parameters | awk -F ',' '{print $3}')
if [ "$method" = 'copy' ] || [ "$method" = 'move' ]; then
for file in "${array[@]}"; do
name=${file##*/}
if [ -f "$file" ] && [[ "$file" == *.* ]]
then newName="${name%.*}${sufix}.${name##*.}"
else newName="${name}${sufix}"
fi
if [ "$method" = 'move' ]
then mv "$file" "${dir}/${newName}"
else cp -r "$file" "${dir}/${newName}"
fi
done
else
newName="${sufix}.${method}"
7z a "$newName" ${array[@]}
fi
kdialog --title "Backup files" --icon "checkbox" --passivepopup "Completed" 3