-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.sh
More file actions
40 lines (32 loc) · 717 Bytes
/
backup.sh
File metadata and controls
40 lines (32 loc) · 717 Bytes
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
#!/bin/bash
if [[ $# != 2 ]]
then
echo "backup.sh target_directory_name destination_directory_name"
exit
fi
if [[ ! -d $1 ]] || [[ ! -d $2 ]]
then
echo "Invalid directory path provided"
exit
fi
targetDirectory=$1
destinationDirectory=$2
echo $targetDirectory
echo $destinationDirectory
currentTS=`date +%s`
backupFileName="backup-[$currentTS].tar.gz"
origAbsPath=$(pwd)
cd $destinationDirectory
destDirAbsPath=$(pwd)
cd $origAbsPath
cd $targetDirectory
let yesterdayTS=$currentTS-86400
declare -a toBackup
for file in $(ls)
do
if ((`date -r $file +%s` > $yesterdayTS))
then toBackup+=($file)
fi
done
tar -czvf $backupFileName ${toBackup[@]}
mv ./$backupFileName $destDirAbsPath/$backupFileName