mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
aad5a5bcb9
the backup command will make consistent snapshots of all the database files. i had been copying the db files before, and it usually works. but if the file is modified during the backup, it is inconsistent and is likely to generate errors when reading (can be at any moment in the future, when reading some db page). "mox backup" opens the database file and writes out a copy in a transaction. it also duplicates the message files. before doing a restore, you could run "mox verifydata" on the to-be-restored "data" directory. it check the database files, and compares the message files with the database. the new "gentestdata" subcommand generates a basic "data" directory, with a queue and a few accounts. we will use it in the future along with "verifydata" to test upgrades from old version to the latest version. both when going to the next version, and when skipping several versions. the script test-upgrades.sh executes these tests and doesn't do anything at the moment, because no releases have this subcommand yet. inspired by a failed upgrade attempt of a pre-release version.
54 lines
1.7 KiB
Bash
Executable file
54 lines
1.7 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# todo: should we also test with mox.conf and domains.conf files? should "mox backup" and "mox gentestdata" add them, and "mox verifydata" use them?
|
|
|
|
set -e
|
|
# set -x
|
|
|
|
(rm -r testdata/upgrade 2>/dev/null || exit 0)
|
|
mkdir testdata/upgrade
|
|
cd testdata/upgrade
|
|
|
|
# Check that we can upgrade what we currently generate.
|
|
../../mox gentestdata data
|
|
../../mox verifydata data
|
|
rm -r data
|
|
|
|
# For each historic release (i.e. all tagged versions) except the first few that
|
|
# didn't have the gentestdata command, we generate a data directory for testing
|
|
# and simulate upgrade to currently checked out version.
|
|
# The awk command reverses the tags, so we try the previous release first since
|
|
# it is the most likely to fail.
|
|
tagsrev=$(git tag --sort creatordate | grep -v '^v0\.0\.[123]$' | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }')
|
|
if test "$tagsrev" = ""; then exit 0; fi
|
|
for tag in $tagsrev; do
|
|
echo "Testing upgrade from $tag to current."
|
|
mkdir $tag
|
|
(CGO_ENABLED=0 GOBIN=$PWD/$tag go install github.com/mjl-/mox@$tag)
|
|
# Generate with historic release.
|
|
./$tag/mox gentestdata $tag/data
|
|
# Verify with current code.
|
|
../../mox verifydata $tag/data
|
|
rm -r $tag/data
|
|
done
|
|
|
|
# Also go step-wise through each released version. Having upgraded step by step
|
|
# can have added more schema upgrades to the database files.
|
|
tags=$(git tag --sort creatordate | grep -v '^v0\.0\.[123]$' | cat)
|
|
first=yes
|
|
for tag in $tags; do
|
|
if test "$first" = yes; then
|
|
echo "Starting with test data for $tag."
|
|
./$tag/mox gentestdata stepdata
|
|
first=
|
|
else
|
|
echo "Upgrade data to $tag."
|
|
./$tag/mox verifydata stepdata
|
|
fi
|
|
done
|
|
echo "Testing final upgrade to current."
|
|
../../mox verifydata stepdata
|
|
rm -r stepdata
|
|
rm */mox
|
|
cd ../..
|
|
rmdir testdata/upgrade/* testdata/upgrade
|