4

I have backups for my current MySQL database and related data but I ask generally, is it safe to do the following?

apt-get update nginx mysql-server php-fpm php-mysql
apt-get upgrade nginx mysql-server php-fpm php-mysql

I do use unattended-upgrades defaultly, only for security upgrades, but I do feel I should upgrade LEMP entirely due to performance needs.

BTW, I know CMs like Ansible do just that (if indeed, it's a basically-all-default LEMP).

  • 4
    Upgrading the packages will not put you on the 'latest' versions available from developers, it'll only put you on the latest update within the repositories you have on your system. Nor will it necessarily improve performance. – Thomas Ward Apr 13 '18 at 13:05
  • 3
    update merely refreshes the database of available packages. Do not attempt to limit update. – user535733 Apr 13 '18 at 16:21

3 Answers3

3

There are no 100% guarantees

If no one else has reported a problem you can be 99% sure. If you find via google search one user has a problem on a different hardware problem your certainty drops to 95%. If a user had a problem for your manufacturer your certainty drops to 90%. If the problem was for your model its 80%, your OS its 70%, etc.

Test, test and test. When finished test again.

The best way of testing is to come in after hours when the database is down and all users are signed off. Create a partition equal to the size of your programs and data. Clone the live partition to the test partition.

Run the upgrade on the test partition:

  • If the upgrade crashes on the test partition thank your lucky stars you didn't do it on the live partition.
  • Fix any errors in the upgrade process, reclone live data to test partition (it will be shorter second time around if rsync is used). Run the upgrade again.
  • After successful upgrade, test your programs. If they crash thank your lucky stars you didn't do it on the live partition.
  • Find out why the programs crashed. If they scrambled your database, reclone the live database, upgrade, get patches for failing programs, retest.

I think you get the picture. To assist in the cloning process you can refer to this script: Bash script to clone Ubuntu to new partition for testing 18.04 LTS upgrade. You can also boot with a Live USB and manually clone with live partition not mounted using the script as a reference coupled with other instructions from the Internet.

Note: The linked script was written on April 28 and works fine. I'm revising it with extra tests to validate the correct test partition is selected as a clone. Another revision is to display Source and Target partition OS version details. The final revision is to display rsync stats for deleted files which are relevant when re-cloning over top of a clone.

dessert
  • 39,982
0

short awnser is yes it is safe
long awnser yes and no depending on how old the software is
the reason i mention age is that if you were to, for an extreem example here, have software from 1999 and are going to update it to the version of 2018 then you will walk into compatabilty issues as the newest version might not be able to convert files from that long ago but if it is more recent then it should be okay.

but if you want to be absolutely sure i say make a backup of the program before updating it

delfiler
  • 237
0

Why shouldn't it be safe? It's always good to have a backup just in case, but for the most part, upgrading packages through apt is safe. I've never encountered an issue when upgrading my LEMP stack, which I've had for at least a few months now. Also, if you're upgrading for performance, you may want to switch from MySQL to MariaDB, which can be done with:

sudo apt install mariadb-server-10.0 mariadb-client-10.0

and it should detect the MySQL databases, and import them.

With both MySQL and MariaDB, backing up the DB is easy, just run:

sudo mysqldump dbnamehere > database.sql

and if something goes wrong during the upgrade, simply restore the database with:

sudo mysql dbnamehere < database.sql

Or, if something went incredible wrong, simply delete the DB, make a new, empty one, and then run the above command.

A few more notes:

  • Please use apt instead of apt-get
  • Just run apt update, and not apt update nginx mysql-server php-fpm php-mysql

Also, if you're using a VPS instead of a dedicated server, VPS providers generally give you the option to create snapshots which are easy to restore to if something goes wrong.

user8292439
  • 3,808