PostgreSQL support added to django-export
A month ago I found django-export on github. django-export is a great Django app to export a database dump and media files with support to export to Amazon S3
The only problem with it was that django-export did not support PostgreSQL which is many Django developers’ database of choice. To solve this I forked Arne Brodowski’s django-export on github and added support for PostgreSQL databases. The result is is available on github
The main issue with PostgreSQL is that there is no way to pass the password in the command line. To work around this problem, I used the .pgpass file. Here’s the set of commands I used:
# Assume that $HOST, $PORT, $DATABASE, $USER and $PASSWORD have been set # Create empty .pgpass if it didn't exist touch ~/.pgpass # Make a copy of current .pgpass mv ~/.pgpass ~/.pgpass.bak # Add entry to .pgpass echo "$HOST:$PORT:$DATABASE:$USER:$PASSWORD" > ~/.pgpass # Apply proper permissions chmod 600 ~/.pgpass # pg_dump piped to bzip (as per django-export) pg_dump -h $HOST -p $PORT -U $USER $DATABASE | bzip2 -c # Restore original .pgpass (will restore an empty file if .pgpass did not exist) mv ~/.pgpass.bak ~/.pgpass
Thanks to Arne Brodowski for a a great Django app.
Python GMail SMTP Example « Code Comments
A good simple example on how to connect to GMail’s SMTP service. Works also for Google Apps. The main difference with other SMTP servers is the ehlo/starttls/ehlo sequence after initializing the SMTP object.
mailServer = smtplib.SMTP('smtp.gmail.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmailUser, gmailPassword)
Remote Eclipse workspace using SSH
One of the clients I do development for has requested that I do not keep any copy of the code on my laptop. I wanted to be able to do work remotely from my home office but still be able to use Eclipse as an IDE (ie not using Vim or Emacs through ssh). I have a ubuntu desktop machine setup with Eclipse at my client’s that I use when I’m there. I wanted to be able to use the Eclipse workspace remotely with Eclipse running locally (ie not use vnc or other remote desktop solutions).
My setup:
There is a linux server at the clientss that is accessible externally via ssh. To ssh to the desktop at the client’s I need to first ssh to the server and then from there ssh to the desktop. If you have direct access to the desktop you can skip the first step of the instructions.
laptop ---- INTERNET ----> Server ---- LOCAL NETWORK ----> Desktop
Prerequisites:
- You need linux/unix machines all the way (I have ubuntu on the laptop, remote desktop and Fedora on the remote server. IT should work with Macs too)
- Install and run an ssh server on the server and remote desktop (openssh) and open apropriate firewall ports.
Instructions:
- Setup ‘direct’ ssh connection to remote desktop:
- Create an ssh tunnel via port forwarding of port 2222 locally to port 22 (ssh) on the remote desktop at the client’s (192.168.1.43 is the local ip of the remote desktop at the client’s and server.company.com is the address of the remote server (facing the internet):
ssh -L 2222:192.168.1.43:22 server.company.com
This terminal should stay opened to keep the tunnel working. - To make sure it works, open a new terminal and connect to the desktop at the client’s (since the local port 2222 is forwarded to port 22 on the desktop at the client’s) :
ssh -p 2222 localhost
- Create an ssh tunnel via port forwarding of port 2222 locally to port 22 (ssh) on the remote desktop at the client’s (192.168.1.43 is the local ip of the remote desktop at the client’s and server.company.com is the address of the remote server (facing the internet):
- Use sshfs to mount my remote desktop home folder on my laptop (on ubuntu you can install with ‘sudo apt-get install sshfs’):
- Create a folder to mount on locally:
mkdir ~/remotedesktop - Create an entry in .ssh/config for the server:
host remotedesktop Hostname localhost Port 2222 - Mount the remote desktop home folder locally:
sshfs remotedesktop: ~/remotedesktop
By default sshfs will mount the home directory but you can specify a path after the semi-column to mount something else.
- Create a folder to mount on locally:
Voilá! Now you can open Eclipse and point to the the workspace on the remotedesktop:
~/remotedesktop/path/to/workspace
And since you’re tunneling through ssh everything is encrypted.
To unmount the remote desktop home folder:
fusermount -u ~/remotedesktop
After than you can close the terminal that was maintaining the ssh tunnel.
Xen and UFW (ubuntu)
I spent a couple of hours today tracking down a problem with a ubuntu server Dom0: the DomUs’ network would not work properly, communication to the Dom0 was the only thing that worked. The problem was that I had enabled ufw and by default ufw will drop Forward requests which is used by the bridged (default) networking in Xen.
If disabling ufw is not an option, the solution is to edit ‘/etc/default/ufw’ and change the value of DEFAULT_FORWARD_POLICY to ACCEPT.
The sed way:
sed -i -e's/DEFAULT_FORWARD_POLICY="DROP"/DEFAULT_FORWARD_POLICY="ACCEPT"/' /etc/default/ufw
Leave a Comment