Moving A Unifi Database To A New Partition Location

Shehu Awwal
Shehu Awwal
Published in
2 min readAug 4, 2019

I was asked to check on the Unifi Controller not working, The issue was the Unifi Web not working, I restart the machine and restart all services but still the error still persists not loading through the web, After doing some research, I came across that once the disk usage of the machine is lower than 3GB, Unifi won’t load, Then I asked my Boss to add more storage to the Linux Machine about 100GB, But I was unable to extend the Root Partition because of LVM, So I just have to use the Storage and make a file partition type.

Finding Unifi Controller Logs

If you wish to find the logs and probably delete some of them due to space,

cd /usr/lib/unifi/logs

I deleted those logs in other to get more space and it worked fine, Then immediately the storage filled up again, So we concluded in adding another Storage.

And I use LVM for the new attached storage, which is /dev/xvdb1

Moving Unifi Database To New Partition

The new partition has been mounted to a directory I created with Unifi in root directory. Make sure you do everything as a root user.

# df -hFilesystem                                 Size   Used      Avail            Use%        Mounted on
/dev/xvda1 48G 45G 199M 100% /
/dev/mapper/External_Storage-Unifi 99G 34G 61G 36% /Unifi

The mounted directory /Unifi is own by the user and group called unifi , And created a subdirectory called unifi-db.

Copy The Entire Unifi Dababase from /var/lib/unifi/db To /Unifi/unifi-db, This /Unifi/unifi-db can be named anything according to what you wish, This is just my naming.

Stop The Unifi Services First

# /etc/init.d/unifi stop

Then Sync The Directory

# rysnc -av /var/lib/unifi/db /Unifi/unifi-db

You can make use of cp, But you would have to start dealing with file permissions, ownership and other things,.

Then rename the old database, to old, You can think of deleting,

# mv /var/lib/unifi/db /var/lib/unifi/db-old

We renamed the db to db-old , Because we can’t delete yet until everything works fine, Then just symlink the directory.

# ln -s /Unifi/unifi-db /var/lib/unifi/db

Start The Services Again

# /etc/init.d/unifi start

And move to root directory — Dont’ forget: root directory /

Then Download this Mongo Compact Script Using wget

# wget https://help.ubnt.com/hc/article_attachments/115024095828/mongo_prune_js.js

And then re-run database script:

# mongo --port 27117 < mongo_prune_js.js

And wait, That’s all, And the partition is already added to fstab.

Source: Thanks to the Unifi community

--

--

Shehu Awwal
Shehu Awwal

Hacker — Passionate About InfoSec, Linux, Clouds, Containers, Virtualization, Distributed Systems And Architectures And New Trends.