Entradas

Mostrando entradas de diciembre, 2014

Backup and restore a postgresql DB

Some times I need to backup and restore a postgresql DB,
I used to have these commands on a stick note but its better to have them here :)
with practice I improved my commands to do them better and better :) here are two of the ones I use:

To backup:

pg_dump -h localhost -p 5432 -U postgres -Fc mydb  > mydb_$(date +"%Y_%m_%d").dump

-h is the host where is the name or ip of the server where your database is running -p is the port of the server -U is the username -Fc means Output a custom-format archive suitable for input into pg_restore mydb is the name of your database > means where you are sending the output to  and $(date +"%Y_%m_%d") add the current date to your file
To Restore:
Tip: when I need to restore and 'overwrite' the actual database, I found only two ways to do it: one is to delete the database and create a new one and restore it after that, but that could not work properly if you dont have the right permissions to do it. So, the second way i…

Setup MongoDB on Linux

Due to there is no a facility for linux, I will post here some steps to do it: Install mongodbInstall Pip, virtualenv and virtualenvwrapperInstall pymongo and bottleInstall MongoDB sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10create this file /etc/apt/sources.list.d/mongodb.list and add this to itdeb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gensudo apt-get updatesudo apt-get install mongodb-orgstart pymongo servicesudo service mongod startInstall pip, virtualenv, virtualenvwrapper sudo apt-get install python-dev python-pip -ysudo pip install virtualenvsudo pip install virtualenvwrappermkdir ~/.virtualenvsadd this lines at the end of your .bashrc file, open it with gedit or vimvim .bashrcexport WORKON_HOME=~/.virtualenvs. /usr/local/bin/virtualenvwrapper.shsave and close .bashrcto make it work restart your terminal or run . .bashrc on itcreate a new virtual enviroment withmkvirtualenv mongodevuse the command workon to start your virtuale…