Sure, sorry if my phrasing was clumsy, as you surely noticed Iām not a native english speaker. Iām aware of the āinclusive writtingā in french but no idea if āsā
he will [ā¦] for hā
imā
er to rollbackā makes sense in english, feel free to propose if you have nicer way to express that.
Oh, maybe not. But again, itās just to help the user, not to replace hā
imā
er. Sā
he still have the last word on whether sā
he wants to run it or not.
This scary warning is really important, I agree. But it also has the downside that some people may think that itās really pointless to try to upgrade somehow this number, and they may end up with old/unmaintained/unsecure packages without even realizing. I do like the fact that you can see the year in that number, as people may wonder at some point āoh, this number is super old, maybe I could try to see what it means and how/why I could migrate it. The warning tells me not to change it directly, I will read more.ā.
That would be definitely a great idea, and it could definitely help, with or without a helper script (both would be complementary of each other).
Actually, Iām thinking that if nix does not want a helper script inside nix, we can still write it ouside nix, and eventually package it as a standard nix package, with a command which could look like:
$ upgrade-state-version --current-state 17.09 --new-state 19.03
DISCLAIMER: upgrading the system state is potentially dangerous
and can lead to data lose.
This script CANNOT detect all unusual configuration, and is just
provided as a helper script. DO CHECK what command it does,
and first do a BACKUP of all your data.
We detected that the following modules are installed and should be migrated:
- [1] postgresql
- [2] nextcloud
In a first step, you will be asked to review the migrating code for each module. You will be able to check the options of the script and then you will have the choice to:
- abort the whole migration: a
- validate the script: v
- edit the script: e
- skip the script (you will then need to perform the migration for that module manually): s
At the end of the review process, you will need to do a last confirmation step
in order to actually run all the validated scripts. At the end, you should be able to change:
Should we continue?[y/n] y
#### Review of migration of postgresql ####
Are you thinking of automatically migrating postgresql?[y/n] y
What is the path of the current database?
(/var/lib/postgresql/9.6/ was detected, simply press Return to validate it)
What is the path of the new database?
(/var/lib/postgresql/11.1/ is proposed, simply press Return to validate it)
The script to update postgresql will be the following:
## This script migrates the database from postgresql_9_6 to postgresql_11
set -e
export NEWBIN="$(nix eval --raw nixpkgs.postgresql_11.outPath)/bin"
export OLDBIN="$(nix eval --raw nixpkgs.postgresql_9_6.outPath)/bin"
export OLDDATA=/var/lib/postgresql/9.6/
export NEWDATA=/var/lib/postgresql/11.1/
# Create the database folder
install -d -m 0700 -o postgres -g postgres "$NEWDATA"
cd "$NEWDATA"
# Initialize the database folder
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
# Stop the old postgresql
systemctl stop postgresql
# Migrate the database
sudo -u postgres $NEWBIN/pg_upgrade \
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
--old-bindir $OLDBIN --new-bindir $NEWBIN
do you want to Validate, Edit, Skip or Abort?[v/e/s/a]
v
The postgresql migration is validated.
#### Review of migration of nextcloud ####
Are you thinking of automatically migrating nextcloud?[y/n] n
The nextcloud migration is skiped.
#### Last confirmation ####
The script that you will run is the following:
## This script migrates the database from postgresql_9_6 to postgresql_11
set -e
export NEWBIN="$(nix eval --raw nixpkgs.postgresql_11.outPath)/bin"
export OLDBIN="$(nix eval --raw nixpkgs.postgresql_9_6.outPath)/bin"
export OLDDATA=/var/lib/postgresql/9.6/
export NEWDATA=/var/lib/postgresql/11.1/
# Create the database folder
install -d -m 0700 -o postgres -g postgres "$NEWDATA"
cd "$NEWDATA"
# Initialize the database folder
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
# Stop the old postgresql
systemctl stop postgresql
# Migrate the database
sudo -u postgres $NEWBIN/pg_upgrade \
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
--old-bindir $OLDBIN --new-bindir $NEWBIN
The above migration script has been copied in /tmp/migration_script.sh.
Do you want to run it now and perform the migration?[y/n]y
#### Migration ####
The script will be run...
[...]
Migration done!
Note that you wanted to manually perform the changes for nexcloud, DON'T FORGET to do it !
You can then check the changes by changing in your configuration `system.stateVersion = "20.03"`.