You are not logged in.

#1 2018-01-20 15:02:18

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

[SOLVED] Backup/Restore MariaDB Database by Copying /var/lib/mysql

My Arch Linux server recently broke and I need to perform a fresh install on it. However, I failed to ever create a SQL dump of the MariaDB database using the mysqldump command (I know...). I have booted into the server using an Arch Live USB and have copied out all the files I need, but now am wondering how to back up the SQL database. Since I'm planning to go from the same version of Arch and MariaDB to the same version of Arch and MariaDB, if I copy over all the files in /var/lib/mysql, will that do the trick? To clarify, I'd copy the files to an external drive, wipe the system and complete the fresh Arch (and MariaDB) installation on it, and then overwrite the new /var/lib/mysql folder with my backup. Does anyone know if this would work or if there's a better way? Thanks.

Last edited by tony5429 (2018-01-21 13:51:46)

Offline

#2 2018-01-20 15:06:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [SOLVED] Backup/Restore MariaDB Database by Copying /var/lib/mysql

I can't offer an answer to the question you're actually asking, but I'm wondering why there isn't a different one being asked:

tony5429 wrote:

My Arch Linux server recently broke and I need to perform a fresh install on it.

In what way is it "broke" that a fresh install would be a reasonable solution?  Just fix it.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2018-01-20 15:10:10

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Backup/Restore MariaDB Database by Copying /var/lib/mysql

Trilby wrote:

I can't offer an answer to the question you're actually asking, but I'm wondering why there isn't a different one being asked:

tony5429 wrote:

My Arch Linux server recently broke and I need to perform a fresh install on it.

In what way is it "broke" that a fresh install would be a reasonable solution?  Just fix it.

I should have explained a little better. To clarify, some booting issues arose after a system upgrade a few days ago. I did a bit of searching around the forums but wasn't able to come to a solution, and I think a fresh install may solve the problem so I'd like to try it.

Offline

#4 2018-01-20 15:15:40

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: [SOLVED] Backup/Restore MariaDB Database by Copying /var/lib/mysql

I'm pretty sure you can in fact drop in /var/lib/mysql after you get the mariadb package installed.  Recommend you install the package, remove or rename /var/lib/mysqld (that the package created) then drop in the old one and replicate the permissions and ownership.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2018-01-20 15:19:39

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Backup/Restore MariaDB Database by Copying /var/lib/mysql

graysky wrote:

I'm pretty sure you can in fact drop in /var/lib/mysql after you get the mariadb package installed.  Recommend you install the package, remove or rename /var/lib/mysqld (that the package created) then drop in the old one and replicate the permissions and ownership.

Thanks for the info and tip. Sounds like a good plan; I hadn't thought about permissions/ownership - that will be good to have the default folder structure renamed so I can compare them side-by-side and adjust things accordingly. OK, I'm going to give it a shot. FIngers crossed!

Offline

#6 2018-01-20 15:23:20

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: [SOLVED] Backup/Restore MariaDB Database by Copying /var/lib/mysql

Probably should have recommended that you stop the service if it's running, but that seems too obvious smile

EDIT: Also, don't recursively apply the chown and chmod command... just to /var/lib/mysqld if needed.  All of the permissions/ownerships for files under that should not change relative to your old install.

Last edited by graysky (2018-01-20 15:25:27)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#7 2018-01-20 16:57:39

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Backup/Restore MariaDB Database by Copying /var/lib/mysql

graysky wrote:

Probably should have recommended that you stop the service if it's running, but that seems too obvious smile

EDIT: Also, don't recursively apply the chown and chmod command... just to /var/lib/mysqld if needed.  All of the permissions/ownerships for files under that should not change relative to your old install.

I haven't been able to get the service to start again, otherwise I'd just run mysqldump smile

I actually haven't wiped the system just yet. I was thinking, to preserve the file permissions / directory structure / etc, could I just make a tarball like this and then decompress it later?

tar cvpzf db.tar.gz /var/lib/mysql
mv /var/lib/mysql /var/lib/mysql_backup
tar xpvzf db.tar.gz

Offline

#8 2018-01-21 13:51:06

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Backup/Restore MariaDB Database by Copying /var/lib/mysql

This plan (using a tarball to backup/restore the db) worked perfectly!

Offline

Board footer

Powered by FluxBB