Created Repair MongoDB (markdown)

Lauri Ojansivu 2022-01-26 01:55:56 +02:00
parent 21ae83d856
commit 4276750994

110
Repair-MongoDB.md Normal file

@ -0,0 +1,110 @@
Some customer of [WeKan Commercial Support](https://wekan.team/commercial-support/) ordered repair of WeKan MongoDB database at Univention appliance. Docker containers were all the time crashing and restarting. Here are commands that were used while repairing.
1. SSH to Univention as root.
```
ssh root@192.168.0.100
```
2. If backup or raw database files is at external USB harddrive, look where it is inserted:
```
ls /dev
fdisk -l /dev/sdc
fdisk -l /dev/sdc
fdisk -l /dev/sdd
```
2. If external USB drive has NTFS file format, install NTFS support to Linux:
```
apt install ntfs-3g
```
3. Mount USB drive to /mnt
```
mount /dev/sdd1 /mnt
```
4. Stop WeKan Docker containers. If copying raw database files, WeKan and MongoDB should not be running, so that MongoDB would not be even more corrupted. (If MongoDB is running, and you have mongodump backup, you can [Backup with mongorestore](https://github.com/wekan/wekan/wiki/Backup)
```
docker stop wekan-db wekan-app
```
5. Find WeKan database raw files. MongoDB has various database engines, like WiredTiger, how to save raw data compressed, or other formats. WiredTiger is file format to save compressed MongoDB data. Similar like MySQL has ISAM, InnoDB etc.
```
apt -y install mlocate
updatedb
locate WiredTiger.wt
```
It can show for example USB drive and Docker container directory:
```
root@ucs:/mnt/wekan/data/db# locate WiredTiger.wt
/mnt/wekan/data/db/WiredTiger.wt
/var/lib/univention-appcenter/apps/wekan/data/db/WiredTiger.wt
```
6. Find mongod command:
```
locate /usr/bin/mongod
```
7. Repair Docker WeKan with version of Docker MongoDB that WeKan uses, change mongod path to below. Repairing logged to textfile.
```
root@ucs:~# /var/lib/docker/overlay2/7b58483a16a2f67ee50486c00ec669940f7a95d460ee8188966fee0096e81fa2/diff/usr/bin/mongod --dbpath "/var/lib/univention-appcenter/apps/wekan/data/db" --repair >> repairlog.txt
```
8. Look what containers are running:
```
docker ps
```
9. Look what containers are not running:
```
docker ps -a
```
10. Start MongoDB first:
```
docker start wekan-db
```
11. Look what happends at MongoDB container:
```
docker logs wekan-db
```
12. Start WeKan next.
```
docker start wekan-app
```
11. Look what happends at MongoDB container.
```
docker logs wekan-app
```
12. Check are both wekan-db and wekan-app containers running, and not restarting:
```
docker ps
```
13. Try to login to WeKan with webbrowser.
14. Backup WeKan database now after repair:
```
docker exec -it wekan-db bash
cd /data
rm -rf dump
mongodump
exit
docker cp wekan-db:/data/dump .
zip -r wekan-backup-2022-01-01.zip dump
```
Now backup is at wekan-backup-2022-01-01.zip file.
15. Transfer file to your local computer with scp:
```
scp root@192.168.0.100:/root/wekan-backup-2022-01-01.zip .
```
16. Copy backup to external USB harddrive:
```
cp /root/wekan-backup-2022-01-01.zip /mnt/
```
17. Look what drives are mounted:
```
df -h
```
18. Sync and save unwritted data to disk, and unmount external USB harddrive safely:
```
sync
umount /mnt
```
19. Remove external USB harddisk from server.