Checking terminal command before I ruin my Mac

Perhaps basic questions, but I’m stuck and answers are quite difficult to goggle.

I need to extract certain data from a Ubiquity Unifi Controller backup. I have a shell script that supposedly can do this.
First step of the instructions is a terminal command of which I don’t know what it does, can anybody enlighten me? Later I need to find out how to run a sh script, typing the script’s line one by one is said to be wrong, but what is correct instead?

sudo apt update && sudo apt install zip unzip openssl mongo-tools

Apparently apt doesn’t even exist on Macs. I read it’s a package manager, so are we talking installing software?
What update is meant here?
And why would I need to install “zip”, “unzip” and “openssl”? Surely these three are part of macOS (for me Ventura).
Maybe mongotools does not exist on Mac as a default. From where are these tools downloaded, no target web address is given.

I’m going to recklessly answer. Let’s see how far off I am…

The shell script was written for a Linux environment that uses the Debian package manager. The commands are updating the package manager’s catalog, and then installing the zip, unzip, openssl, and mongo-tools packages. Mongo-tools are command line tools for MongoDB.

macOS comes with openssl. It doesn’t come with command line zip or unzip, and certainly not mongo-tools.

The advice would be to use a macOS package manager to install these packages. Fink has been problematic for several macOS releases, so that leaves Homebrew or MacPorts.

Many people like Homebrew. I’m disturbed by Homebrew’s approach to security.

2 Likes

I admire your enthusiasm and sense of adventure! You are wise to be cautious when running shell commands and scripts, especially when they require use of the sudo prefix (effectively running as the all-powerful root user).

I entered the following prompt into ChatGPT and got back what on first review looks like a sane and helpful step-by-step process (actually, two different approaches–the first of which includes some of the same advice @mschmitt gave you) to accomplish your goal: “I’m using a Mac computer. How do I extract data from a Ubiquity Unifi Controller backup?”

Give that a try, and see if the response is helpful to you.

2 Likes

@mschmitt Thanks for the reckless answer, very helpful. :grinning:
@fischej A very interesting approach with ChatGPT. Unfortunately, it didn’t work. ChatGPT invented a command line tool on Github that doesn’t exist, and it invented a user who supposedly had written it. It kept on guessing other approaches, like renaming a .unf to .zip, which doesn’t work either. It now gives me a a complex Python script which I won’t try, the trust is gone.

In the meantime one other aspect came to light: Once I have located the data I need (a combination of username/password for SSH) I still have to crack open the string I might find. Apparently doable, but I’m getting quickly into an unknown territory. I’m not THAT adventurous, I’m talking after all about a building with 6 WiFi Access points that are all working at this time.

2 Likes

Man, I hate it when “Chatty” can’t seem to make up her mind. Apologies to other thread readers for the length, but here’s the response I got:

To extract data from a Ubiquity Unifi Controller backup on your Mac, follow these steps:

  1. Locate the Backup File:

    • The backup file typically has a .unf extension. Make sure you know where the file is located on your computer.
  2. Install MongoDB Tools:

    • The Unifi Controller stores its data in a MongoDB database. You’ll need MongoDB tools to extract the data from the backup.

    To install MongoDB tools, you can use Homebrew. Open Terminal and run:

    brew tap mongodb/brew
    brew install mongodb-database-tools
    
  3. Extract the Backup:

    • The .unf file is essentially a compressed archive. You can extract it using a tool like unzip.

    Navigate to the directory where your backup file is located:

    cd /path/to/your/backup/file
    unzip your_backup_file.unf -d extracted_backup
    
  4. Locate the MongoDB Database Files:

    • After extracting, you should see files and folders related to the MongoDB database. Look for files like db.<collection>.bson and db.<collection>.metadata.json.
  5. Use mongorestore to Import Data:

    • To import the data into a MongoDB instance, you’ll use the mongorestore tool.

    First, start a local MongoDB instance (if you don’t have one running already). You can start it by running:

    brew services start mongodb/brew/mongodb-community
    

    Then, restore the data:

    mongorestore --drop --dir=extracted_backup
    
  6. Access the Data:

    • Once the data is restored, you can access it using MongoDB tools or a MongoDB GUI client like MongoDB Compass.

    Connect to your MongoDB instance and explore the restored database.

Optional: Use a Docker Container for MongoDB

If you prefer not to install MongoDB directly on your system, you can use a Docker container.

  1. Install Docker Desktop:

  2. Run MongoDB in Docker:

    docker run --name mongodb -d -p 27017:27017 mongo
    
  3. Restore the Backup in Docker:

    docker cp extracted_backup/. mongodb:/data/db
    docker exec -it mongodb mongorestore --drop /data/db
    
  4. Access the Data:

    • Connect to the MongoDB instance running in Docker using MongoDB tools or GUI clients.

By following these steps, you should be able to extract and access data from your Ubiquity Unifi Controller backup on your Mac.

Since when? It’s always been there on my systems since Mac OS X 10.2. On my Sonoma system 14.5 system:

$ which zip
/usr/bin/zip

$ which unzip
/usr/bin/unzip

$ zip
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
Zip 3.0 (July 5th 2008). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  The default action is to add or replace zipfile entries from list, which
  can include the special name - to compress standard input.
  If zipfile and list are omitted, zip compresses stdin to stdout.
  -f   freshen: only changed files  -u   update: only changed or new files
  -d   delete entries in zipfile    -m   move into zipfile (delete OS files)
  -r   recurse into directories     -j   junk (don't record) directory names
  -0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
  -1   compress faster              -9   compress better
  -q   quiet operation              -v   verbose operation/print version info
  -c   add one-line comments        -z   add zipfile comment
  -@   read names from stdin        -o   make zipfile as old as latest entry
  -x   exclude the following names  -i   include only the following names
  -F   fix zipfile (-FF try harder) -D   do not add directory entries
  -A   adjust self-extracting exe   -J   junk zipfile prefix (unzipsfx)
  -T   test zipfile integrity       -X   eXclude eXtra file attributes
  -y   store symbolic links as the link instead of the referenced file
  -e   encrypt                      -n   don't compress these suffixes
  -h2  show more help

No doubt about that. Looking at the MongoDB home page, it appears that their approved installation mechanism is HomeBrew:

1 Like