-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathmail-backup
More file actions
66 lines (53 loc) · 1.73 KB
/
mail-backup
File metadata and controls
66 lines (53 loc) · 1.73 KB
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
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#this script will backup all winlink messages
#to an external thumb drive. You can specify
#the exact path when starting the file or allow
#the script to look for an external drive automatically.
#To specify a path, add it when calling the script.
#example /home/pi/bin/mail-backup ~/Downloads
#28DEC2020 KM4ACK
#sleep for 30 seconds while pi boots
sleep 30
#get pat version
PVERSION=$(pat version | awk -F "." '{print $2}')
#set archive folder
#DO NOT USE SPACES. Use "-" or "_" to serperate words.
ARCH=old-email-backups
#set a few variables
CALL=$(grep MYCALLSIGN ~/patmenu2/config | sed 's/MYCALLSIGN=//')
BKUPTIME=$(date +%Y%m%d-%H%M)
DATE=$(date)
#check to see if user indicated path
#use external drive if not
if [ -z $1 ]; then
DIR=$(ls /media/pi)
#verify we have a path or external drive to work with
if [ -z $DIR ] && [ -z $1 ]; then
echo "External drive not found and backup directory not specified."
echo "$DATE Winlink backup failed. Path not set and external drive not found" >> $HOME/Documents/mylog.txt
exit 1
fi
DIR=/media/pi/$DIR
else
DIR=$1
fi
#create archive dir
mkdir -p $DIR/$ARCH
#move old backups to archive dir
mv $DIR/email.bkup* $DIR/$ARCH/ >/dev/null 2>&1
#create backup dir
mkdir $DIR/email.bkup.$BKUPTIME
#determine correct path depending on pat version
if [ $PVERSION -ge '12' ]; then
BACKUP_COMMAND="cp -r $HOME/.local/share/pat/mailbox/$CALL/* $DIR/email.bkup.$BKUPTIME"
else
BACKUP_COMMAND="cp -r $HOME/.wl2k/mailbox/$CALL/* $DIR/email.bkup.$BKUPTIME"
fi
#copy file to backup dir
$BACKUP_COMMAND
#verify success and write to log file
if [ $? = 0 ]; then
echo "$DATE Winlink messages back up success" >> $HOME/Documents/mylog.txt
else
echo "$DATE Winlink backup failed" >> $HOME/Documents/mylog.txt
fi