Cleaning inventory and device-auth sync commands

Hey Yoann

I have started a new thread @Piocky in order not to trash Mender server deviceauth propagate issue - #22 by peter.
the commands with the inventory db you have to run in the mongo shell:

docker exec -i `docker ps | grep mongo | head -1 | awk '{print($1);}'` mongo

and there

use inventory
db.devices.deleteMany({})

this is assuming you are running docker (I thought you mentioned that). you have to locate your inventory db with show dbs unless you went to some extra work there should be one with the prefix inventory. (it maybe just inventory).
the other commands I was mentioning, just try to run them with help argument and see if they exist:

docker exec -i `docker ps | grep device-auth | head -1 | awk '{print($1);}'` deviceauth propagate-inventory-statuses --help
docker exec -i `docker ps | grep device-auth | head -1 | awk '{print($1);}'` deviceauth propagate-inventory-id-data --help
it

let me know how it goes.

best regards,
peter

1 Like

Hi @peter,

Ok good idea, I thought it was a related issue.

The commands worked, but I’ve lost all the groups that I made… I used that script to save my db:

# more save_db.sh
docker run -it --rm -v db-artifacts:/from -v $PWD:/to -w /from     alpine     ash -c 'tar c * | gzip -9 > /to/db-artifacts-backup.tar.gz'
docker run -it --rm -v mender-artifacts:/from -v $PWD:/to -w /from     alpine     ash -c 'tar c * | gzip -9 > /to/mender-artifacts-backup.tar.gz'
docker run -it --rm -v mender-db:/from -v $PWD:/to -w /from     alpine     ash -c 'tar c * | gzip -9 > /to/mender-db-backup.tar.gz'
docker run -it --rm -v mender-elasticsearch-db:/from -v $PWD:/to -w /from     alpine     ash -c 'tar c * | gzip -9 > /to/mender-elasticsearch-db-backup.tar.gz'
docker run -it --rm -v mender-redis-db:/from -v $PWD:/to -w /from     alpine     ash -c 'tar c * | gzip -9 > /to/mender-redis-db-backup.tar.gz'

But I don’t know how to recover my db from that?

ok, the groups. right. how many did you have?
are the devices all visible?

peter

I’d say around 10-15 maybe.
I see all my devices yes.

send me the mender-db-backup.tar.gz dump peter@northern.tech and I will see what we can do.

peter

Hey Yoann,

it is better to use mongodunp/mongorestore to backup/restore the database.
with the backup you have, you have to run mongo and decompress the archive into data base root (e.g.: the default /data/db or other that you will point mongod to). thats what I did, then in the mongodb shell you can run:

var c=db.devices.find({"attributes.system-group.value":{"$exists":1}},{"attributes.system-group.value":1}).pretty(); while (c.hasNext()) { var e=c.next(); var id=e._id; var group=e.attributes["system-group"].value; print('db.devices.updateOne({"_id":"'+id+'"},{"$set":{"attributes.system-group.value":"'+group+'","name":"group","scope":"system"}})'); };

to get the required script to update your database to restore the device groups.
thats what I also did and I sent you the script to run which will restore the groups over email, just run it in the mongo shell of your current database.

best regards,
peter

Hey Peter,

Ok I see, do you have any commands or link(s) for a procedure to follow, so I could improve my save_db script for the future? Is it only for mender-db or for others too?

Sorry for my little knowledge on this, I am not the one that deployed the Mender Server, just the one in charge of maintaining it.

Hey Yoann,

you can refer to 3.1 docs: Backup and restore | Mender documentation
and in general using the mongodump command is a better way to backup than the raw copy of the database data directory.

best regards,
peter

Thanks, so if I understand correctly, I should add ../../migration/dump-db at the end of my save_db.sh file, and if necessary use restore-db to restore the MongoDB DB, right?

should work, and if it does not let me know.

pg

1 Like