Skip to content

Commit

Permalink
fix neo4j dump/load & backup script
Browse files Browse the repository at this point in the history
  • Loading branch information
noboruma committed Jun 10, 2024
1 parent 1c65ff2 commit be80f67
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
29 changes: 6 additions & 23 deletions deepfence_neo4j/backup_neo4j.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
#!/bin/bash

dt=$(date '+%Y-%m-%d_%H-%M-%S');
BACKUP_FILE="/backups/neo4j_backup_$dt.dump"

echo "Backup file is: $BACKUP_FILE"

mkdir -p /backups/

neo4j stop
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Failed to stop the neo4j db"
exit
fi

neo4j-admin database dump neo4j --to-stdout > $BACKUP_FILE
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Failed to create the backup file"
fi

sleep 2s
/startup/docker-entrypoint.sh neo4j >& /dev/null&
kill -USR1 1
sleep 10
while ! neo4j status 1>&2 2>/dev/null; do
echo "Waiting for neo4j to be up..."
sleep 5
done
4 changes: 2 additions & 2 deletions deepfence_neo4j/df.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ backup_db() {
touch /backups/.inprogress
neo4j stop
NOW=$(date +"%Y-%m-%d_%H-%M-%S")
neo4j-admin database dump neo4j --to-stdout > /backups/neo4j_$NOW.dump
neo4j-admin database dump --to-stdout neo4j > /backups/neo4j_$NOW.dump
ls -tr /backups/*.dump | head -n -${MAX_NUM_BACKUPS:-5} | xargs --no-run-if-empty rm
start_db
rm /backups/.inprogress
Expand Down Expand Up @@ -75,7 +75,7 @@ else
echo "Backup already loaded, skipping"
else
echo "Start using backup: $USE_BACKUP"
cat $USE_BACKUP | neo4j-admin database load --from-stdin neo4j --overwrite-destination=true
cat $USE_BACKUP | neo4j-admin database load neo4j --from-stdin --overwrite-destination=true
mv $USE_BACKUP $USE_BACKUP.used
fi
fi
Expand Down

0 comments on commit be80f67

Please sign in to comment.