Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions emoncms-copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,33 @@ backup_location="/home/pi/usbdisk/backup"


#-----------------------------------------------------------------------------------------------
# Check emonPi / emonBase image version
# Check container / emonPi / emonBase image version
#-----------------------------------------------------------------------------------------------
image_version=$(ls /boot | grep emonSD)
# Check first 16 characters of filename
image_date=${image_version:0:16}

if [[ "${image_version:0:6}" == "emonSD" ]]
then
echo "Image version: $image_version"
fi

# Detect if SD card image verion, used to restore the correct emonhub.conf
if [[ "$image_date" == "emonSD-17Jun2015" ]]
then
image="old"
if [ -f "/.dockerenv" ]; then
echo "running in container"
else
image="new"
image_version=$(ls /boot | grep emonSD)
# Check first 16 characters of filename
image_date=${image_version:0:16}

if [[ "${image_version:0:6}" == "emonSD" ]]
then
echo "Image version: $image_version"
fi

# Detect if SD card image verion, used to restore the correct emonhub.conf
if [[ "$image_date" == "emonSD-17Jun2015" ]]
then
image="old"
else
image="new"
fi
fi

#-----------------------------------------------------------------------------------------------

sudo systemctl stop feedwriter
if [ ! -f "/.dockerenv" ]; then
sudo systemctl stop feedwriter
fi

# Get MYSQL authentication details from settings.php
if [ -f /home/pi/backup/get_emoncms_mysql_auth.php ]; then
Expand Down Expand Up @@ -85,7 +90,9 @@ cp /home/pi/data/node-red/settings.js $backup_location
cp --verbose -r /home/pi/data/phpfina/. $backup_location/phpfina
cp --verbose -r /home/pi/data/phptimeseries/. $backup_location/phptimeseries

sudo systemctl start feedwriter > /dev/null
if [ ! -f "/.dockerenv" ]; then
sudo systemctl start feedwriter > /dev/null
fi

date
echo "=== Emoncms export complete! ===" # This string is identified in the interface to stop ongoing AJAX calls, please ammend in interface if changed here
60 changes: 39 additions & 21 deletions emoncms-export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,43 @@ for file in "${backup_location}/emoncms.sql" "${tar_filename}"
do
if [ -f "${file}" ]
then
sudo rm "${file}"
if [ -f "/.dockerenv" ]; then
rm "${file}"
else
sudo rm "${file}"
fi
fi
done

#-----------------------------------------------------------------------------------------------
# Check emonPi / emonBase image version
# Check container / emonPi / emonBase image version
#-----------------------------------------------------------------------------------------------
image_version=$(cd /boot && echo *emonSD* )
# Check first 16 characters of filename
image_date=${image_version:0:16}
if [ -f "/.dockerenv" ]; then
echo "running in container"
else
image_version=$(cd /boot && echo *emonSD* )
# Check first 16 characters of filename
image_date=${image_version:0:16}

if [[ "${image_version:0:6}" == "emonSD" ]]
then
echo "Image version: $image_version"
fi
if [[ "${image_version:0:6}" == "emonSD" ]]
then
echo "Image version: $image_version"
fi

# Very old images (the ones shipped with kickstarter campaign) have "emonpi-28May2015"
if [[ -z $image_version ]] || [[ "$image_date" == "emonSD-17Jun2015" ]]
then
image="old"
else
image="new"
# Very old images (the ones shipped with kickstarter campaign) have "emonpi-28May2015"
if [[ -z $image_version ]] || [[ "$image_date" == "emonSD-17Jun2015" ]]
then
image="old"
else
image="new"
fi
fi
#-----------------------------------------------------------------------------------------------

# Disabled in @borphin commit?
sudo systemctl stop feedwriter
# Disabled in @borpin commit?
if [ ! -f "/.dockerenv" ]; then
sudo systemctl stop feedwriter
fi

# Get MYSQL authentication details from settings.php
if [ -f "${script_location}/get_emoncms_mysql_auth.php" ]; then
Expand All @@ -101,7 +111,9 @@ if [ -f "${script_location}/get_emoncms_mysql_auth.php" ]; then
else
echo "Error: cannot read MYSQL authentication details from Emoncms $script_location/get_emoncms_mysql_auth.php php & settings.php"
echo "$PWD"
sudo systemctl start feedwriter > /dev/null
if [ ! -f "/.dockerenv" ]; then
sudo systemctl start feedwriter > /dev/null
fi
exit 1
fi

Expand All @@ -111,12 +123,16 @@ if [ -n "$username" ]; then # if username string is not empty
if [ $? -ne 0 ]; then
echo "Error: failed to export mysql data"
echo "emoncms export failed"
sudo systemctl start feedwriter > /dev/null
if [ ! -f "/.dockerenv" ]; then
sudo systemctl start feedwriter > /dev/null
fi
exit 1
fi
else
echo "Error: Cannot read MYSQL authentication details from Emoncms settings.php"
sudo systemctl start feedwriter > /dev/null
if [ ! -f "/.dockerenv" ]; then
sudo systemctl start feedwriter > /dev/null
fi
exit 1
fi

Expand Down Expand Up @@ -151,7 +167,9 @@ do
fi
done

sudo systemctl start feedwriter > /dev/null
if [ ! -f "/.dockerenv" ]; then
sudo systemctl start feedwriter > /dev/null
fi

# Compress backup
echo "Compressing archive..."
Expand Down
Loading