2020-09-26 16:19:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# ScoDoc: save all user data (database, configs, images, archives...) in separate directory
|
|
|
|
#
|
|
|
|
# Utile pour migrer ScoDoc d'un serveur a un autre
|
|
|
|
# Executer en tant que root sur le serveur d'origine
|
|
|
|
#
|
|
|
|
# E. Viennet, Sept 2011, Aug 2020
|
|
|
|
#
|
2020-12-05 17:29:26 +01:00
|
|
|
source utils.sh
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Destination directory
|
|
|
|
if [ ! $# -eq 1 ]
|
|
|
|
then
|
|
|
|
echo "Usage: $0 destination_directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
DEST=$1
|
|
|
|
# remove trailing slashs if needed:
|
|
|
|
shopt -s extglob
|
|
|
|
DEST="${DEST%%+(/)}"
|
|
|
|
|
|
|
|
if [ ! -e "$DEST" ]
|
|
|
|
then
|
|
|
|
echo Creating directory "$DEST"
|
|
|
|
mkdir "$DEST"
|
|
|
|
else
|
|
|
|
echo "Error: Directory " "$DEST" " exists"
|
|
|
|
echo "remove it or specify another destination !"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
INSTANCE_DIR=/opt/scodoc
|
|
|
|
SCODOC_DIR="$INSTANCE_DIR/Products/ScoDoc"
|
|
|
|
|
|
|
|
source utils.sh
|
2020-12-28 22:09:20 +01:00
|
|
|
check_uid_root "$0"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
echo "Stopping ScoDoc..."
|
2020-12-05 17:29:26 +01:00
|
|
|
scodocctl stop
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Dump all postgres databases
|
|
|
|
echo "Dumping SQL database..."
|
|
|
|
chown postgres "$DEST"
|
|
|
|
su -c "pg_dumpall > \"$DEST\"/scodoc.dump.txt" postgres
|
2020-12-28 22:09:20 +01:00
|
|
|
if [ ! "$?" -eq 0 ]
|
2020-09-26 16:19:37 +02:00
|
|
|
then
|
2020-12-28 22:09:20 +01:00
|
|
|
printf "Error dumping postgresql database\nPlease check that SQL server is running\nAborting."
|
2020-09-26 16:19:37 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
chown root "$DEST"
|
|
|
|
|
|
|
|
# Zope DB and ScoDoc archives:
|
|
|
|
echo "Copying var/ ..."
|
|
|
|
cp -rp "$INSTANCE_DIR/var" "$DEST"
|
|
|
|
|
|
|
|
# Depts db config (now in .../var)
|
|
|
|
shopt -s nullglob
|
2020-12-28 22:09:20 +01:00
|
|
|
if [ -n "$(echo ${SCODOC_DIR}/config/depts/*.cfg)" ]
|
2020-09-26 16:19:37 +02:00
|
|
|
then
|
|
|
|
echo "Copying legacy depts configs..."
|
|
|
|
cp -rp "$SCODOC_DIR/config/depts" "$DEST"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Photos des etudiants (now in .../var)
|
|
|
|
if [ -e "$SCODOC_DIR/static/photos" ]
|
|
|
|
then
|
|
|
|
echo "Copying legacy photos..."
|
|
|
|
cp -rp "$SCODOC_DIR/static/photos" "$DEST"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Copying logos..."
|
|
|
|
cp -rp "$SCODOC_DIR/logos" "$DEST"
|
|
|
|
|
|
|
|
echo "Copying configuration file..."
|
|
|
|
cp -p "$SCODOC_DIR/config/scodoc_config.py" "$DEST"
|
|
|
|
|
|
|
|
echo "Copying server logs..."
|
|
|
|
cp -rp "$INSTANCE_DIR/log" "$DEST"
|
|
|
|
|
|
|
|
|
|
|
|
# --- Archive all files in a tarball to ease transfer
|
|
|
|
echo
|
|
|
|
echo "Archiving backup files in a $DEST.tgz..."
|
|
|
|
base=$(basename "$DEST")
|
2020-12-28 22:09:20 +01:00
|
|
|
(cd "$DEST"/.. || terminate "directory error"; tar cfz "$DEST".tgz "$base")
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
echo "Done (you can copy " "$DEST"".tgz to destination machine)."
|