I've seen the mongodump command used to export a specific database, but how can I find the name of the available databases before choosing one?
To confirm, is this correct?
mongodump -d <database_name> -o <directory_backup>
Also, what effect will the command alone, without any flags, have if run on the database? Thanks!
You can show the databases available with
show dbs
If you do not specify a database it will dump all databases.
https://docs.mongodb.com/manual/reference/program/mongodump/#cmdoption--db
Related
Im currently using the tool pg_dump to backup my database.
I have a lot of database. I don't know their full name but I know that all DATABASES have a well defined prefix.
I would like to automate the process of backup all my DATABASES, however, i have not found a way to specify pg_dump to dump multiple DATABASE that have the same prefix.
I said database and not table nor schema, because I tried the commands in the pgsql doc which gives the options -n for schemas and -t for tables.
But that's not what I want to do, I want to save all my databases with a defined prefix.
Any help in this matter would be greatly appreciated
I have an un-updated local Postgres server, running on a docker container, now I want to update all new records from Production DB,
which runs on Azure Postgres DB.
I'm aware of the pg_dump as in this Answer
but, I'm not clear where should I commend it - the Azure DB doesn't know the Local one and vice versa?
There are multiple methods which you can try.
The most common and simple approach is to use pg_dump and pg_restore commands in bash to upgrade the database.
In above mentioned method, you first create a dump from the source server using pg_dump. Then you restore that dump file to the target server using pg_restore.
To back up an existing PostgreSQL database, run the following command:
pg_dump -Fc -v --host=<host> --username=<name> --dbname=<database name> -f <database>.dump
Once the file has been created, download it in local environment.
After you've created the target database, you can use the pg_restore command and the --dbname parameter to restore the data into the target database from the dump file.
pg_restore -v --no-owner --host=<server name> --port=<port> --username=<user-name> --dbname=<target database name> <database>.dump
To find more upgrade methods, you can refer https://learn.microsoft.com/en-us/azure/postgresql/how-to-upgrade-using-dump-and-restore#method-1-using-pg_dump-and-psql.
To get more details on pg_dump and pg_restore methood, please refer Microsoft Official document Migrate your PostgreSQL database by using dump and restore.
I must restore a single Mongodb database from a full backup of many databases
without touching the other databases:
e.g. $ mongorestore --gzip --drop --db ONEDB dbbackupfile
Will the restore command honour the --db ONEDB and ONLY drop the ONEDB database collection? Or will it drop them all?
[The documentation for mongorestore only says that --drop will drop all collections in the backup - it doesn't say what effect the --db option has on the --drop flag...]
Thank you in advance for your help.
I understand the fear of dropping all your databases,
With that being said the documentation clearly states:
drops the collections from the target database.
i recommend that if your experimenting with this command for the first time and you're not confident with it yet you should test it not on production but on your local first, or at the very least run it with --dryRun flag just to see if your getting the results you want.
I have two postgres databases on the same server, a live one and another one which I use as a test database.
Periodically I need to copy my live database (both structure of the tables and their data) into the test one, but everything I've found online only copies table by table. Since I often create new tables in my live db I can't do this, otherwise I'd have to update the job every time.
Anybody knows how can I pull the whole live postgres db into the test postgres one?
Thanks!
You want to use pg_dump and pg_restore.
Example usage would be:
$ pg_dump -Fc <database_name> > dumpfile
$ pg_restore <another_database_name> < dumpfile
If you want to do this for all database you might want to consider pg_dumpall
A bit more can be found in https://www.postgresql.org/docs/current/backup-dump.html
I am trying to restore the directory dump of mongodb.
i am doing
mongorestore --db mydb --drop path/to/mydb/dump
But both does not able to restore the state of my dump.
Any new records are visible even after restoring the db.
But no error is shown on console.
I didn't see an answer and I had the same question today.
You can drop the database before with:
use <db>
db.dropDatabase()
Or you can only drop the collection with:
db.<collection>.drop()
The problem with your command could be that something misses, like the database which you authenticate against or the user or maybe another thing.
In my setup this works
mongorestore --username=<user> --db=<database> --authenticationDatabase=<database> --dir=<dumpdir> --drop
If your dump was zipped beforehand, you can add the --gzip flag in the end.
You can find all that in the documentation for dropping a database or in the documentation of dropping a whole database. But please be cautious with it.