How to deploy mysql database to server via ssh - phing

I try to use Phing for deploying site to the server.
Command which should create database or make changes:
<pdosqlexec url="mysql:host=${db.host}; dbname=${db.name}"
userid="${db.user}"
password="${db.pass}"
src="${project.basedir}/deploy/mysqlbuiltscripts/create_database.sql"/>
It works good on local machine. But I need to make changes on server too.
Main problem - I have access to server database via SSH only.
Question - How can I execute this command via SSH tunnel?
P.S. I tried to use <ssh username="${username}" password="${password}" host="${host}" command="${myMysqlCommand}">, but it does not suit me because it does not write changes to Phing "changelog" table.

Are you using dbdeployTask? If you are generating a delta for the remote server, then your file should have the changelog present.
If you don't have access to your remote server, you may need to do the dbdeploy work on the remote server directly or tunnel your requests through ssh.
My dbdeploy steps are:
Run phing -> dbdeploy task
Get a delta sql
With mysql, run the delta sql script on the remote server
Enjoy

Related

How can I install pgAgent Jobs on a remote server in PostgreSQL?

Locally I have no problems, but on the remote server I want to perform a routine on, it is not possible.
I also specified a connection string locally to perform the routine on the remote server, but it does not work.

Does Postgres use local resources when connecting to a server?

I am new to Postgres and wanted to understand if i make a remote server for Postgres and use PGadmin to connect to the remote server, will it use local resources to run the queries?
I tried it on a user machine here and it seems to be the case and would like the queries submitted to be run on the server itself and not consume local resources. Any suggestions would be helpful.
Thanks
Saurabh
No, the query is run on the server. However the download and the display of the results can take some time and can take ressources on the client, depending on the size of the result set.

Entity Framework - I want the database to be created on a different SQL Server

My EF tutorial project works fine on a machine with SQL Server installed, but when I move the project to a machine with no SQL Server installed, the code below fails:
Database.SetInitializer(new DropCreateDatabaseAlways<EmployeeDb>());
I'd like to get the project working on a machine which has only the SQL Server client not the server. I've experimented with connection strings in app.config without success. Help much appreciated.
you have install SQL server in separate machine and configure to connect from other systems and put that machine name(or IP address) in connection string.
Configure the Windows Firewall to Allow SQL Server Access
how-to-enable-remote-connections-in-sql-server-2008

How do I get started if I want to use PostgreSQL for local use?

Good day,
Currently I use MS Access at home for several Databases (for personal use).
At work, I use PostgreSQL, which is infinity times better. I want to start using postgres for my personally used databases, but I don't know where to start.
I've tried reading the documentation, but still don't know how to start. I don't have a server at home; is it possible I can just make a local database/tablespace? Or would I have to host a virtual server?
Note that I am willing to use other open source databases if there is an easy option out there - MS access is just so... terrible.
Thanks,
So, it seems you have Windows at home. You just need to download full installer for PostgreSQL:
http://www.postgresql.org/download/windows/
After installation it will automatically add starting postgres server as a service on local machine. That means, server will always run in background, but you can disable that later, or just uninstall.
After that, you can use pgAdmin (included in default installation package) or other client tools to access the DB engine.
UPD in pgadmin, create connection with this settings:
'localhost' as hostname;
port - 5432;
user, database - postgres (for testing purpose only - you should create your own user and tables with restricted rights later).
Password for postgres (that is DB admin user) must be entered during installation process.
Server settings are stored somewhere here:
"C:\Program Files\PostgreSQL\9.3\data"
pg_hba.conf - Client Authentication Configuration File
postgresql.conf - Configuration File

Remote trigger a postgres database backup

I would like to backup my production database before and after running a database migration from my deploy server (not the database server) I've got a Postgresql 8.4 server sitting on a CentOS 5 machine. The website accessing the database is on a Windows 2008 server running an MVC.Net application, it checks out changes in the source code, compiles the project, runs any DB Changes, then deploys to IIS.
I have the DB server set up to do a crontab job backup for daily backups, but I also want a way of calling a backup from the deploy server during the deploy process. From what I can figure out, there isn't a way to tell the database from a client connection to back itself up. If I call pg_dump from the web server as part of the deploy script it will create the backup on the web server (not desirable). I've looked at the COPY command, and it probably won't give me what I want. MS SQLServer lets you call the BACKUP command from within a DB Connection which will put the backups on the database machine.
I found this post about MySQL, and that it's not a supported feature in MySQL. Is Postgres the same? Remote backup of MySQL database
What would be the best way to accomplish this? I thought about creating a small application that makes an SSH connection to the DB Server, then calls pg_dump? This would mean I'm storing SSH connection information on the server, which I'd really rather not do if possible.
Create a database user pgbackup and assign him read-only privileges to all your database tables.
Setup a new OS user pgbackup on CentOS server with a /bin/bash shell.
Login as pgbackup and create a pair of ssh authentication keys without passphrase, and allow this user to login using generated private key:
su - pgbackup
ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -N ""
cp -a ~/.ssh/.id_rsa.pub ~/.ssh/authorized_keys
Create a file ~pgbackup/.bash_profile:
exec pg_dump databasename --file=`date +databasename-%F-%H-%M-%S-%N.sql`
Setup your script on Windows to connect using ssh and authorize using primary key. It will not be able to do anything besides creating a database backup, so it would be reasonably safe.
I think this could be possible if you create a trigger that uses the PostgreSQL module dblink to make a remote database connection from within PL/pgSQL.
I'm not sure what you mean but I think you can just use pg_dump from your Windows computer:
pg_dump --host=centos-server-name > backup.sql
You'd need to install Windows version of PostgreSQL there, so pg_dump.exe would be installed, but you don't need to start PostgreSQL service or even create a tablespace there.
Hi Mike you are correct,
Using the pg_dump we can save the backup only on the local system. In our case we have created a script on the db server for taking the base backup. We have created a expect script on another server which run the script on database server.
All our servers are linux servers , we have done this using the shell script.