Backup MySQL and Nginx Configurations

Hello,

My DigitalOcean server filesystem got corrupted and I’m trying to recover the data. I’m not able to SSH in, so the DO guys mounted recovery ISO for me to backup the data. I’m now taking a back up of my /var/www directory.

Is there any way I can backup my existing nginx configuration and the MySQL DBs so that I can setup everything on a new DO droplet?

Thanks

Hi @arjunskumar47

You can find all the nginx configuration under /etc/nginx /etc/nginx/sites-availabe/ /etc/nginx/sites-enabled/ (symlinks)

And for backing up mysql use mysqldump

mysqldump -uroot-p<password> DB_name > dbname.sql

And restore it using

mysql -uroot -ppassword < dbname.sql

@anto

Thanks for the reply. I don’t have the nginx directory inside /etc in the recovery ISO that’s mounted as well as the mysql command is not recognized.

Hi @arjunskumar47

In this case you can

  1. stop mysql service on old and new server
  2. mv /var/lib/mysql /var/lib/mysql-bk (In new server)
  3. rsync all files under /var/lib/mysql to new Server (copying all files under /var/lib/mysql to new server)
  4. chown -R mysql: /var/lib/mysql
  5. start mysql service

check whether the databases are showing up or not. If the db files are not corrupted, this will be successful.

And the case of nginx configuration,

  1. Create domains without db using EE in in new server (ee site create domain.com --html)
  2. rm -rf /var/www/domain.com/htdocs/*
  3. copy /var/www/domain.com/htdocs/* from old to new server
  4. chown -R www-data: /var/www/domain.com/htdocs
1 Like

Thank you @anto . Had to work a little more in getting the exact config back, though you pointed me in the right direction.

Thanks again! :slight_smile: