Skip to content

Commit d901189

Browse files
add export to usbdisk script
1 parent f86ed05 commit d901189

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

emoncms-copy.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
date=$(date +"%Y-%m-%d")
4+
5+
echo "=== Emoncms export start ==="
6+
date
7+
echo "EUID: $EUID"
8+
echo "Reading /home/pi/backup/config.cfg...."
9+
if [ -f /home/pi/backup/config.cfg ]
10+
then
11+
source /home/pi/backup/config.cfg
12+
echo "Location of mysql database: $mysql_path"
13+
echo "Location of emonhub.conf: $emonhub_config_path"
14+
echo "Location of emoncms.conf: $emoncms_config_path"
15+
echo "Location of Emoncms: $emoncms_location"
16+
echo "Backup destination: $backup_location"
17+
else
18+
echo "ERROR: Backup /home/pi/backup/config.cfg file does not exist"
19+
exit 1
20+
fi
21+
22+
backup_location="/home/pi/usbdisk/backup"
23+
24+
#-----------------------------------------------------------------------------------------------
25+
# Remove Old backup files
26+
#-----------------------------------------------------------------------------------------------
27+
#if [ -f $backup_location/emoncms.sql ]
28+
#then
29+
# sudo rm $backup_location/emoncms.sql
30+
#fi
31+
32+
33+
#-----------------------------------------------------------------------------------------------
34+
# Check emonPi / emonBase image version
35+
#-----------------------------------------------------------------------------------------------
36+
image_version=$(ls /boot | grep emonSD)
37+
# Check first 16 characters of filename
38+
image_date=${image_version:0:16}
39+
40+
if [[ "${image_version:0:6}" == "emonSD" ]]
41+
then
42+
echo "Image version: $image_version"
43+
fi
44+
45+
# Detect if SD card image verion, used to restore the correct emonhub.conf
46+
if [[ "$image_date" == "emonSD-17Jun2015" ]]
47+
then
48+
image="old"
49+
else
50+
image="new"
51+
fi
52+
53+
#-----------------------------------------------------------------------------------------------
54+
55+
sudo service feedwriter stop
56+
57+
# Get MYSQL authentication details from settings.php
58+
if [ -f /home/pi/backup/get_emoncms_mysql_auth.php ]; then
59+
auth=$(echo $emoncms_location | php /home/pi/backup/get_emoncms_mysql_auth.php php)
60+
IFS=":" read username password <<< "$auth"
61+
else
62+
echo "Error: cannot read MYSQL authentication details from Emoncms settings.php"
63+
echo "$PWD"
64+
exit 1
65+
fi
66+
67+
# MYSQL Dump Emoncms database
68+
if [ -n "$username" ]; then # if username sring is not empty
69+
mysqldump -u$username -p$password emoncms > $backup_location/emoncms.sql
70+
else
71+
echo "Error: Cannot read MYSQL authentication details from Emoncms settings.php"
72+
exit 1
73+
fi
74+
75+
echo "Emoncms MYSQL database dump complete, adding files to archive .."
76+
77+
cp $emonhub_config_path/emonhub.conf $backup_location
78+
cp $emoncms_config_path/emoncms.conf $backup_location
79+
cp $emoncms_location/settings.php $backup_location
80+
cp /home/pi/data/node-red/flows_emonpi.json $backup_location
81+
cp /home/pi/data/node-red/settings.js $backup_location
82+
83+
# Append database folder to the archive with absolute path
84+
#cp --verbose -r /home/pi/$mysql_path $backup_location
85+
cp --verbose -r /home/pi/data/phpfina/. $backup_location/phpfina
86+
cp --verbose -r /home/pi/data/phptimeseries/. $backup_location/phptimeseries
87+
88+
sudo service feedwriter start > /dev/null
89+
90+
date
91+
echo "=== Emoncms export complete! ===" # This string is identified in the interface to stop ongoing AJAX calls, please ammend in interface if changed here

emoncms-export.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ echo "Emoncms MYSQL database dump complete, adding files to archive .."
8282
tar -cf $backup_location/emoncms-backup-$date.tar $backup_location/emoncms.sql $emonhub_config_path/emonhub.conf $emoncms_config_path/emoncms.conf $emoncms_location/settings.php /home/pi/data/node-red/flows_emonpi.json /home/pi/data/node-red/flows_emonpi_cred.json /home/pi/data/node-red/settings.js --transform 's?.*/??g'
8383

8484
# Append database folder to the archive with absolute path
85-
tar --append --file=$backup_location/emoncms-backup-$date.tar -C $mysql_path phpfina phptimeseries
85+
tar --append --verbose --file=$backup_location/emoncms-backup-$date.tar -C $mysql_path phpfina phptimeseries
8686

8787
# Compress backup
8888
echo "Compressing archive..."

0 commit comments

Comments
 (0)