Skip to content

Instantly share code, notes, and snippets.

@a2line
Created January 17, 2024 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2line/92c5aef7b50024a6fef8380623dcd8f0 to your computer and use it in GitHub Desktop.
Save a2line/92c5aef7b50024a6fef8380623dcd8f0 to your computer and use it in GitHub Desktop.
Geneweb remote backup (import/export + external tools)
#!/bin/bash
# Set the database name
DATABASE_NAME="mydatabase"
GENEWEB_PORT="2317"
# Set the remote server details
REMOTE_HOST="192.168.2.50"
REMOTE_USER="user"
REMOTE_PASSWORD="password"
# Generate the current date in YYYYMMDD format
CURRENT_DATE=$(date "+%Y%m%d")
# Set the file name
BACKUP_FILE=${DATABASE_NAME}_${CURRENT_DATE}
# Check if the file already exists
if [ -e $BACKUP_FILE.gw ]; then
echo "Error: Backup file '$BACKUP_FILE' already exists. Daily backup is already done. Exiting script."
exit 1
fi
cd bases
# Remote backup Geneweb 6.08 database (plink need to be in /bases [todo: or in path?])
./plink.exe -ssh $REMOTE_USER@$REMOTE_HOST -pw $REMOTE_PASSWORD "cd /home/geneweb/bases; /usr/share/geneweb/gw/gwu $DATABASE_NAME" > ${BACKUP_FILE}.gw
# Check the last line of the file
LAST_LINE=$(tail -n 1 ${BACKUP_FILE}.gw)
# Check if the last line contains "end page-ext"
if echo "$LAST_LINE" | grep -q "end page-ext"; then
echo "Backup completed successfully."
else
echo "Error: The last line does not contain 'end page-ext'. Exiting script."
exit 1
fi
# Compress the backup using WinRAR5 [todo: zip or tar.gz?]
/cygdrive/c/progra~1/winrar/rar.exe a -m5 -md1024 -s -r3p -t -k "${BACKUP_FILE}.rar" ${BACKUP_FILE}.gw
# Create cache_files for Insee deaths files
./insee ${DATABASE_NAME} > /cygdrive/g/insee2/todo.lst
# Import backup file (.gw) to local Geneweb 7.x
../gw/gwc -nofail -f "${DATABASE_NAME}_${CURRENT_DATE}.gw" -o "$DATABASE_NAME" -stats -cg
# Update nldb tool
../gw/update_nldb ${DATABASE_NAME}
# Connex tool
../gw/connex -a -s -gwd_p ${GENEWEB_PORT} ${DATABASE_NAME} > ${DATABASE_NAME}.gwb/notes_d/connex.txt
# Remove temporary import file (.gwo)
rm "${BACKUP_FILE}.gwo"
# Open database in Chrome
cygstart "http://localhost:${GENEWEB_PORT}/${DATABASE_NAME}_w"
# Start GWD
cd ..
OCAMLPARAM=b gw/gwd -robot_xcl 180,210 -p ${GENEWEB_PORT} -allowed_tags bases/tags.txt -log "<stderr>" -blang -log_level 7 >> log.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment