2

How ?

When trying to create a chrooted environment for some users, I end up using

mount --rebind <path> <newPath>

In order to allow chrooted users to access some useful command (a bad practice, yeah)

After some discussions with a colleague, I've change my mind and decide to use groups to blacklist some folder to chrooted users. After doing some

umount <path>

I end up doing a little rm -rf . to clean the last folder

The worst idea I've ever have

Sadly I have forget to umount the /usr/share folder and rm start to delete file in this directory. Hopefully I've done a quick

Ctrl + C

After i've noticed my mistakes. I was like "Cool there isn't too much damage"

I was really wrong.

All my services (mysql ; postregsql ; java) can't run anymore because they needed dependencies in /etc/alternatives Running a

update-alternatives --force --all

Help me a little bit but doesnt help starting mysql. I've totally lost faith in fixing this so i'd like to made a backup of every configurations file and perform a clean install of my vps. But like you think

I have no database backup

I know this is really really wrong, please forgive me.


My question

Now let's move on my question, is there a way to restore PostreSQL and MySQL connection in order to backup the database and save it to perform a clean install on my VPS ? Or I'm i totally lost ?

So far I've tried :

  • recreate database socket (doesn't really work)
  • regenerate mysql data files and move my blocks files into the folder (It help running back mysql, I can see the database and the table using SHOW DATABASES; and SHOW TABLES; but i can't access them)

Notes

In the futur I'll make backup, I promise

Update :

According to PostreSQL : https://www.postgresql.org/docs/9.1/static/backup-file.html there is a way to backup database using fs. I'll try that


Thank's for take the time to read me, hope you'll have and idea.

creekorful
  • 130
  • 7

3 Answers3

1

Generally you restore from backup, or if the data lost was critical find a new job.

Generally I'd suggest using a data recovery service but that requires immediately shutting down the device after the accident happens.. It's also very expensive and time intensive.

Tim Brigham
  • 15,465
  • 7
  • 72
  • 113
  • Its a side project there is no worries about data. But i'd like to try to extract table from mysql block file instead of loosing everything – creekorful Jan 24 '18 at 21:46
1

For thoses who wonder if there is a solution, I've finally found one !

First I've download gdrive a Google Drive terminal client.

Then I've made several backup of all important directory (/home, /etc/nginx, ...) And for my MySQL and PostgreSQL server I've back up the following directory :

  • /var/lib/mysql <-- for MySQL
  • /var/lib/postgresql/9.3/main <-- for PostgreSQL

I've uploaded theses backup on my Google Drive and reinstall my VPS

Finally I've reinstall MySQL server stopped the daemon, backup the original /var/lib/mysql and download from Google Drive my old one. And after a little bit of fix on permission, the server has started ! And voila my database are back and functionnal !

I've not tested PostgreSQL data reimport but I think It'll work, i'll try tomorrow.

Anyway that will be a good lesson for me : no matter what, always perform backup !

Update

Just finish importing my PostgreSQL dump, nothing was lost !

creekorful
  • 130
  • 7
1

Apart from configuring daily / hourly back ups it is always good practice to back up specifically the folders you are going to work on just before touching your system, and this rule becomes even more important if it’s a production environment.

In your case, I’d look at mysqldump and the equivalent of postgres.

Itai Ganot
  • 10,424
  • 27
  • 88
  • 143
  • Thank for your suggestion ! But my problem is solved. I've tried to use mysqldump but because of the missing configuration I didn't succeed. However backup fs has work – creekorful Jan 25 '18 at 08:02