IoT - NodeRED - Backup

According to node-red cookbook all files in the .node-red subdirectory should be backuped - except files in "node-modules" sub-directory:

 I made a short script to backup the relevant files:

#!/bin/bash
#
# uncomment for verbose output
#
# set -x
#
# (c) DL2SBA 27.10.2018
#
#
echo "-------------------- starting node red backup ---------------"
# MOUNT_SOURCE="//ds213/backup"
MOUNT_TARGET="/mnt/backup"
MOUNT_USER="USER"
MOUNT_PASSWD="PASS"
NODE_RED_ROOT=/home/nodered
NODE_RED_FOLDER=myNodeRed
TARGET_DIR=$MOUNT_TARGET/Nodes/node-red/NODE-RED
TARGET_FILE=$TARGEt_DIR/node-red.` date +%Y%m%d_%H%M%S`.tar.gz

#
# check for mounted backup directory
#
if [ -d "$MOUNT_DIR" ]; then
echo "--- mounting ..."
# Mount the network share
#
mount -v -t cifs -o user=$MOUNT_USER,password=$MOUNT_PASSWD,rw,file_mode=0777,dir_mode=0777,uid=$MOUNT_USER,gid=users,vers=2.0 $MOUNT_SOURCE $MOUNT_TARGET
#
echo "--- mounted"
fi

#
# backup node-red data
#
cd $NODE_RED_ROOT
tar -cvzf $TARGET_FILE --exclude="$NODE_RED_FOLDER/node_modules" $NODE_RED_FOLDER
#
echo "-------------------- node red backup DONE ---------------"

 

 

 

Daily backup

Add this line to the crontab of root

sudo crontab -u root -e
10 5 * * * /home/nodered/backupNodeRed.sh  | /usr/bin/logger -t noderedbackup