how to run a Mongo db script on a remote server?
I know below command can be used for the same on local as mentioned here:How to execute mongo commands through shell scripts?
mongo < yourFile.js
I want to run this script on a remote server
mongodb:uri:mongodb://user:password#mongodb01d.mydomain.com:27017/mydb
With Mongo on local machine :
mongo -u <user> -p <password> mongodb01d.mydomain.com:27017/mydb <yourFile.js>
It might be a little bit off topic, but in case you want to / have to use Powershell for a lack of options, you can run:
(Get-Content yourFile.js) | & mongo.exe 'mongodb://user:password#mongodb01d.mydomain.com:27017/mydb'
or
"print('Hello');print('Hello')" | & mongo.exe 'mongodb://user:password#mongodb01d.mydomain.com:27017/mydb'
or
& 'mongo.exe' 'mongodb://user:password#mongodb01d.mydomain.com:27017/mydb' --eval "print('Hello');print('Hello')"
I had some difficulties with $regex, because Powershell interpreted it as a variable, so I had to use `$regex (with an additional backtick) instead.
Related
I have an application that (I want to) uses Java to start and stop Docker containers. It seems that the way to do this is using docker-machine create, which works fine when I test from the command line.
However, when running using Commons-Exec from Java I get the error:
(aa4567c1-058f-46ae-9e97-56fb8b45211c) Creating SSH key...
Error creating machine: Error in driver during machine creation: /usr/local/bin/VBoxManage modifyvm aa4567c1-058f-46ae-9e97-56fb8b45211c --firmware bios --bioslogofadein off --bioslogofadeout off --bioslogodisplaytime 0 --biosbootmenu disabled --ostype Linux26_64 --cpus 1 --memory 1024 --acpi on --ioapic on --rtcuseutc on --natdnshostresolver1 off --natdnsproxy1 on --cpuhotplug off --pae on --hpet on --hwvirtex on --nestedpaging on --largepages on --vtxvpid on --accelerate3d off --boot1 dvd failed:
VBoxManage: error: Could not find a registered machine with UUID {aa4567c1-058f-46ae-9e97-56fb8b45211c}
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "FindMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())" at line 500 of file VBoxManageModifyVM.cpp
I have set my VBOX_USER_HOME variable in an initializationScript that I'm using to start the machine:
export WORKERID=$1
export VBOX_USER_HOME=/Users/me/Library/VirtualBox
# create the machine
docker-machine create $WORKERID && \ # create the worker using docker-machine
eval $(docker-machine env $WORKERID) && \ # load the env of the newly created machine
docker run -d myimage
And I'm executing this from Java via the Commons Exec CommandLine class:
CommandLine cmdline = new CommandLine("/bin/sh");
cmdline.addArgument(initializeWorkerScript.getAbsolutePath());
cmdline.addArgument("test");
Executor executor = new DefaultExecutor();
If there is another library that can interface with docker-machine from Java I'm happy to use that, or to change out Commons Exec if that's the issue (though I don't understand why). The basic requirement is that I have some way to get docker-machine to create a machine using Java and then later to be able to use docker-machine to stop that machine.
As it turns out the example that I posted should work, the issue that I was having is that I was provisioning machines with a UUID name. That name contained dash (-) characters which apparently break VBoxManage. This might be because of some kind of path problem but I'm just speculating. When I changed my UUID to have dot (.) instead of dash it loaded and started the machine just fine.
I'm happy to remove this post if the moderators want, but will leave it up here in case people are looking for solutions to problems with docker-machine create naming issues.
I Installed Postgresql-9.5 and PgAdmin III in my CentOS 6.6, i use these commands,
1) service postgresql-9.5 status
2) service postgresql-9.5 start
3) su postgres
4) psql
5) password
6) mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.mysql -u root -p databasename
7) mysqldump -u root -p --compatible=postgres databasename < /home/databasename.mysql
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=#OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE /;
/!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS /;
/!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS /;
/!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
-- Dump completed on 2017-08-28 11:42:14
Once it completed i open my PgAdmin III and check there is nothing... No data present inside my Database. What mistake I done.
mysqldump can't be used for executing SQL commands from file - you need to use something like psql: psql -h hostname -d databasename -U username -f file.sql.
You need to create database before using this command (so remove create database from file).
UNLOCK TABLES; That will throw error in PostgreSQL, you need to remove that line.
An insanely easy approach will be to use NMIG an amazing script with near 0 config needed.
Clone the repo
npm i, npm run build
Set your MySQL and Postgres servers connections in the ./config/config.json
npm start
Enjoy your migrated db
I am now working on a docker project with two docker containers - one for the oracle db and the other with a java application.
The container for oracle db is working ok. I used the already built image for oracle and created my tablespaces and users in it.
Commands I used to pull and use the oracle db container is as given below:
docker pull wnameless/oracle-xe-11g
docker run -d -p 49160:22 -p 49161:1521 -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g
Now I have my own Java application that interacts with the oracle db and I run it using the command given below:
docker run -it --name mypgm myrepo/oracletesting
It runs an interactive java program that asks for the Oracle DB details and allows users to interact with the DB.
However I could not figure out how I have to specify details such as
Driver Name, Connection URL, Username, and Password
The values I gave are as given below:
Driver Name: oracle.jdbc.OracleDriver
Connection URL:jdbc:oracle:thin:#localhost:1521:orcl11g
Username: imtheuser
Password: **********
I dont know whats going wrong where but its not working.
I tried giving different inputs for Connection URL after inspecting the docker container ip address as well:
Connection URL: jdbc:oracle:thin:#172.17.0.2:1521:orcl11g
Am I giving the Connection URL and/or the port number correct? Can someone help me out to correctly connect these two containers and to get the project moving?
Thanks for your kind help..
You have to link the containers.
The oracle container should have a name.
try the following:
docker network create my-network # Create a network for containers
docker run -d -p 49160:22 -p 49161:1521 --network my-network --name oracle-db -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g
docker run -it --network my-network --name mypgm myrepo/oracletesting
Use as connection url to following string jdbc:oracle:thin:#oracle-db:1521:orcl11g
You can use a domain name in oracle connection string: oracle.dbhost.com, and use a --addhost oracle.dbhost.com:[ip address] when running your app in docker, or configure a dns to resolve the domain name.
I don't find my answer on any post.
I use a container with a project under PHP on a container which works fine. I want to link Java which is launch on another container.
I use the "java:8" image configure like this :
engine:
build: ./docker/engine/
volumes:
- ".:/home/docker:rw"
- "./docker/engine/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
links:
- "db:db"
- "java:java"
working_dir: "/home/docker"
java:
image: java:8
tty: true
ports:
- "999:999"
On my docker PHP container (call "engine"), I have this environment variable.
JAVA_1_ENV_CA_CERTIFICATES_JAVA_VERSION=20140324
JAVA_1_ENV_JAVA_DEBIAN_VERSION=8u72-b15-1~bpo8+1
JAVA_1_ENV_JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JAVA_1_ENV_JAVA_VERSION=8u72
JAVA_1_ENV_LANG=C.UTF-8
JAVA_1_NAME=/recetteetudiant_engine_1/java_1
JAVA_1_PORT=tcp://172.17.0.3:999
JAVA_1_PORT_999_TCP=tcp://172.17.0.3:999
JAVA_1_PORT_999_TCP_ADDR=172.17.0.3
JAVA_1_PORT_999_TCP_PORT=999
JAVA_1_PORT_999_TCP_PROTO=tcp
JAVA_ENV_CA_CERTIFICATES_JAVA_VERSION=20140324
JAVA_ENV_JAVA_DEBIAN_VERSION=8u72-b15-1~bpo8+1
JAVA_ENV_JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JAVA_ENV_JAVA_VERSION=8u72
JAVA_ENV_LANG=C.UTF-8
JAVA_NAME=/recetteetudiant_engine_1/java
JAVA_PORT=tcp://172.17.0.3:999
JAVA_PORT_999_TCP=tcp://172.17.0.3:999
JAVA_PORT_999_TCP_ADDR=172.17.0.3
JAVA_PORT_999_TCP_PORT=999
JAVA_PORT_999_TCP_PROTO=tcp
RECETTEETUDIANT_JAVA_1_ENV_CA_CERTIFICATES_JAVA_VERSION=20140324
RECETTEETUDIANT_JAVA_1_ENV_JAVA_DEBIAN_VERSION=8u72-b15-1~bpo8+1
RECETTEETUDIANT_JAVA_1_ENV_JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
RECETTEETUDIANT_JAVA_1_ENV_JAVA_VERSION=8u72
RECETTEETUDIANT_JAVA_1_ENV_LANG=C.UTF-8
RECETTEETUDIANT_JAVA_1_NAME=/recetteetudiant_engine_1/recetteetudiant_java_1
RECETTEETUDIANT_JAVA_1_PORT=tcp://172.17.0.3:999
RECETTEETUDIANT_JAVA_1_PORT_999_TCP=tcp://172.17.0.3:999
RECETTEETUDIANT_JAVA_1_PORT_999_TCP_ADDR=172.17.0.3
RECETTEETUDIANT_JAVA_1_PORT_999_TCP_PORT=999
RECETTEETUDIANT_JAVA_1_PORT_999_TCP_PROTO=tcp
Ping command works fine. But how can I use java with that? I try to use that command
root#639144f7c95f:/home/docker# echo $JAVA_1_PORT$RECETTEETUDIANT_JAVA_1_ENV_JAVA_HOME
tcp://172.17.0.3:999/usr/lib/jvm/java-8-openjdk-amd64
root#639144f7c95f:/home/docker# /recetteetudiant_engine_1/java_1
bash: /recetteetudiant_engine_1/java_1: No such file or directory
root#639144f7c95f:/home/docker# $JAVA_1_PORT$RECETTEETUDIANT_JAVA_1_ENV_JAVA_HOME
bash: tcp://172.17.0.3:999/usr/lib/jvm/java-8-openjdk-amd64: No such file or directory
root#639144f7c95f:/home/docker#
Maybe I have to share a volume ? Can I use Java through TCP protocol?
You have 2 containers in your compose file. The one which seems to host a php application and one which has java installed.
From "inside" the containers, it behaves as if you had 2 different machines (they are not machines, but containers): one "machine" with a hostname called "engine" and one "machine" with a hostname called "java".
You somehow what to connect to the "machine" called "engine" and run java there. Java application is installed on the other "machine".
What you are trying to do does not seem to make sense.
You can't (or at the very least should not) use java over TCP - not in the way you want to, which seems to be to somehow invoke java executable which is basically on another machine (or docker container in this case). Maybe there is some way to achieve this with some remote call, but even if possible it would still be wrong. Simply add JRE to your php container. Or make your jar work like a WS.
Docker containers are not meant to be used in a way that container1 has java executable so call it from there, container2 has vi, container3 grep etc...
Some ways "interacting" between containers(with one common volume):
Orchestrate in host.
docker exec -t php command-prepare
docker exec -t java-app-jdk java -jar yuicompressor.jar bla-bla
docker exec -t php command-post
Create simple app who listen port and start command in JavaContainer (IMHO best way)
Create "cron" who look volume in JavaContainer, for example,
a) phpContainer put files to volume and put "indicator" file
b) javaContainer look "indicator" file, and start work. Post complete remove "indicator" file and put "work log" file.
c) phpContainer wait some time, and get "work log" file. Work depending on the result parse "work log" file.
UPD.
Also you can do something similar to docker.spotter https://github.com/discordianfish/docker-spotter.
I am trying to import database from .sql file in postgres using "\i E:/dump.sql" command , its working fine from postgres command prompt but when i try the same from java it raise an error at "\" , my code is
connection = DriverManager.getConnection( "jdbc:postgresql://localhost:5432/database","postgres", "passwd");
PreparedStatement ps3 = connection.prepareStatement("\\i E:/dump.sql");
boolean res3= ps3.execute();
System.out.println("imported succesfully .."+res3);
With the JDBC driver/interface you can only talk SQL, what you're trying is to issue PostgreSQL commandline tool (psql) specific commands. That won't work.
If you insist on doing this, you could use the Runtime.getRuntime().exec(...) approach, something like
Runtime.getRuntime().exec( "psql -f dump.sql" );
Cheers,
Long story short - you can't. \i is not PostgreSQL command (as in: PostgreSQL database engine). It's command of psql - which is command line tool for interacting with database.
If you're connecting to database via JDBC you're not using psql, so you can't use its commands (\i, \o and alike).