Skip to content

Commit

Permalink
Make backup without tmp and cache (openhab#756)
Browse files Browse the repository at this point in the history
* Make backup without tmp and cache

Changes the backup script so that it doesn't include tmp and cache directories. Add optional --full argument for those who want to include it.

Signed-off-by: Daniel Malmgren <[email protected]> (github: DanielMalmgren)
  • Loading branch information
DanielMalmgren authored and kaikreuzer committed Oct 26, 2018
1 parent 07720ee commit c9d8079
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions distributions/openhab/src/main/resources/bin/backup
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ getFullPath() {

setup(){
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: backup [filename]"
echo "Usage: backup [--full] [filename]"
echo ""
echo " e.g. ./backup << Makes a file with a timed filename"
echo " ./backup myBackup.zip << Makes a file called myBackup.zip"
echo " e.g. ./backup << Makes a file with a timed filename"
echo " ./backup myBackup.zip << Makes a file called myBackup.zip"
echo " ./backup --full << Makes a full backup file with a timed filename"
echo " ./backup --full myBackup.zip << Makes a full backup file called myBackup.zip"
echo ""
echo "Use this script to backup your openHAB configuration, you can use the 'restore' script"
echo "from any machine to transfer your configuration across to another instance."
echo ""
echo "A full backup includes the tmp and cache directories that are normally excluded."
echo ""
echo "Set $OPENHAB_BACKUPS to change the default backup directory."
exit 0
fi
Expand Down Expand Up @@ -55,6 +59,13 @@ setup(){

fileList="$OPENHAB_RUNTIME/bin/userdata_sysfiles.lst"

## Parse arguments
if [ "$1" = "--full" ]; then
echo "including cache"
INCLUDE_CACHE="true"
shift
fi

timestamp=$(date +"%y_%m_%d-%H_%M_%S")
## Set the filename
if [ -z "$1" ]; then
Expand Down Expand Up @@ -96,7 +107,7 @@ echo " openHAB 2.x.x backup script "
echo "#########################################"
echo " "

setup "$1"
setup "$1" "$2"

## Set backup properties file.
{
Expand All @@ -109,7 +120,11 @@ setup "$1"
## Copy userdata and conf folders
echo "Copying configuration to temporary folder..."
mkdir -p "$TempDir/userdata"
cp -a "${OPENHAB_USERDATA:?}/"* "$TempDir/userdata"
if [ -z "$INCLUDE_CACHE" ]; then
find "${OPENHAB_USERDATA:?}/"* -prune -not -path '*/tmp' -and -not -path '*/cache' | xargs -I % cp -R % "$TempDir/userdata"
else
cp -a "${OPENHAB_USERDATA:?}/"* "$TempDir/userdata"
fi
mkdir -p "$TempDir/conf"
cp -a "${OPENHAB_CONF:?}/"* "$TempDir/conf"

Expand Down

0 comments on commit c9d8079

Please sign in to comment.