ARGH
[matches/honours.git] / superbug_backup.sh
1 #!/bin/bash
2
3 if [ "$(ps aux | grep $0)" != "" ]; then
4         echo "Already running!"
5         exit 1
6 fi
7
8 #Script to run on "superbug" to backup to BoB storage
9
10 #target="smb://10.1.1.1/bob2%20usb%20storage/honours"
11 target_directory="sam\honours"
12 update_period=1 #Update this often in minutes
13
14 smb_command="" #"cd $target_directory;"
15 for backup in $(find . -mmin -$update_period -print | grep -v "\.git" | sed 's:^\./::g'); do
16         #echo "$backup"
17         if [ "$backup" != "." ]; then
18                 smb_command=""
19                 if [ "$(stat $backup | head --lines=2 | tail --lines=1 | awk '{print $NF}')" == "directory" ]; then
20                         smb_command="mkdir $target_directory\\$(echo \"$backup\" | sed 's:/:\\:g');"
21                 else
22                         smb_command="put \"$backup\" $target_directory\\\"$(echo $backup | sed 's:/:\\:g')\";"
23                 fi
24                 echo "SMB command: $smb_command"
25                 smbclient -N //10.1.1.1/"BoB2 USB storage" -c "$smb_command"
26         fi
27 done
28
29 exit 0

UCC git Repository :: git.ucc.asn.au