Gitlab full Postgresql backup and restore

GitLab and Posgresql

GitLab can be used with Postgresql as its database engine  (beside MySQL),  and all come ready to make backups and restores of its databases and git repositories by using a ruby script (rake). This is the recommended way because it lets you recover everything wit not pending transactiond on database and Git sides.

The problem

The documentation explains all you have to perform a manual backup and restore, but the latter fails because it tries to insert existing registers that generate conflicts like this one:

psql:/home/git/gitlab/tmp/backups/db/database.sql:812: ERROR: relation "users" already exists

The Solution

The postgresql backup must erase all tables before trying to recreate them and insert the registers. That can be done bu including the  –clean r -c  to the pg_dump command. This option must be edited in the ruby script that makes the backup, which is  /home/git/gitlab/lib/backup/database.rb by default. In this file you have to find this part of code and substitute the following bold line:

require 'yaml'
module Backup
 class Database
 attr_reader :config, :db_dir
def initialize
 @config = YAML.load_file(File.join(Rails.root,'config','database.yml'))[Rails.env]
 @db_dir = File.join(Gitlab.config.backup.path, 'db')
 FileUtils.mkdir_p(@db_dir) unless Dir.exists?(@db_dir)
def dump
 success = case config["adapter"]
 when /^mysql/ then
 print "Dumping MySQL database #{config['database']} ... "
 system('mysqldump', *mysql_args, config['database'], out: db_file_name)
 when "postgresql" then
 print "Dumping PostgreSQL database #{config['database']} ... "
 system('pg_dump', config['database'], out: db_file_name)

This line mus be replaced with this other line:

system('pg_dump', config['database'], '-c', out: db_file_name)

Here you can see that option -c is passed as argument to command pg_dump. This will force to include all DROPS needed in the generated .sql  for the GitLab backup.


No Comments

Course Creative, Serious and Playful Science of Android Apps

Coursera androidapps101 2014 Computer Science and Programming Badge

Recently I received the awards for the Android course Creative, Serious and Playful Science of Android Apps lectured by Lawrence Angrave from University of Illinois at Urbana-Champaign. The course was designed to learn Android programing from scratch, therefore if you are interesting in developing for this platform this is a good starting point. The video lectures were made in English, but there are subtitles for Spanish and even English, so language is not barrier.

The Awards

The awards I earned were these:

  • Statement of Accomplishment:  This is a sort of of certificate which you earn when accomplishing 70% or higher. I got 94.6%
  • Computer Science and Programming Badge: This is a kind of badge they gave you also when you accomplished 70% or higher.

This awards are not part of the Signature Track, which let you share and validate this grade,  but you have to pay $49 for this feature.


No Comments

qBitTorrent Client for Android

qBittorrent Client - UI qBittorrent Client - Torrent action  qBittorrent Client - Add URL

When I subscribed on Coursera’s Android courses I did it because I had and idea for long time: an Android application to manage torrents. With qBittorrent Client you can connect to a qBittorrent server and manage torrents to add, pause, or delete them.


With this first version you be able to:

  • Add URL directly or by clicking it on your device’s browser
  • Pause, resume, delete or delete individual torrents with its downloaded data
  • Set a connexion account

New features

In future releases these features will be available:

  • Auto-update torrents’s status
  • Set qBittorrent server’s settings from device
  • Download notification, even if the application’s UI is not running.
  • Other features

Download application

If you are interested in this application you can download qBittorrent Client as apk to install it on your device. Also you can download the code from GitHub because it was released open source with GPL.



Samsung Galaxy Tab P1000 with Android 4.3 – CyanogenMod 10.2

CyanogenMod 10.1 - Android 4.2.1 - Samsung Galaxy Tab 7 CyanogenMod 10.1 - Android 4.2.1 - Samsung Galaxy Tab 7 CyanogenMod 10.1 - Android 4.2.1 - Samsung Galaxy Tab 7

One more time I wanted to give another breath to my Samsung Galaxy Tab 7, because prices here in Venezuela are not encouraging, so I decided to install Cyanogenmod 10.2 con Android 4.3, thanks to HumberOS. This upgrade is valid only for the Latin American model, I mean Samsung Galaxy Tab 7 P1000N (o P1000L). Here I leave all you need to do so, and some tips.


  • Remember that only you are responsible of what you do to your tablet. Although I followed this method, I won’t take any responsibility if you brick your tablet.
  • Backup your current rom and any data. This will help you to go back if something goes wrong.
  • Do this procedure with at least 75% of battery charge.
  • This rom ONLY works on P1000N / P1000L.


  • To have installed a Recovery  capable of loading updates ( like CWM Recovery)


  1. Download and copy into internal o external sdcard’s root directory files, and The first one is the ROM and the second one are the Googles’ apps for this Android version.
  2. Turn off the tablet and then turn it on in the CWM Recovery by pressing Power On + Volume Up buttons at the same time. When it boots you should see a screen like this one:

     CyanogenMod 10.1 - Android 4.2.1 - Samsung Galaxy Tab 7

  3. Make wipe data / factory reset and wipe dalvik cache on the wipe menu.
  4. On the  Install menu go to choose zip from internal sdcard (or choose zip from external sdcard if it’s your case). Choose  the file to flash it to the tablet.
  5. Later you must install the Google’s apps. To do so you have to go one more time to choose zip from internal sdcard option and choose the file
  6. Once installed, go to reboot menu and reboot the tablet by choosing reboot system. The tablet will boot with the CyanogenMod’s logo. It will last quite a few, don’t turn off the tablet. Be patient.
  7. When it had finished, follow the tablet’s settings wizard, and enjoy it!

IMEI no valid

If you reboot your tablet and got the Invalid IMEI error as show below, I recommend you to got to the Stock ROM 2.3.3, and the update with the HumberOS’s kernel qith grants you root permission,  and finally do the above steps for upgrading to 4.3:

IMEI issue

The process can be a little tedious but it must be done to use a fresh operating system so it can recognize the device’s IMEI.

, , , ,


My first application on Android: BatteryReporter


From a while I wanted to learn how to develop Android applications and when I saw that open a course at Coursera for developing Android appslications so I took the chance to learn. I must confess that it not  a piece of cake, I mean, it just not “copy and paste” code (although you can find example codes out there) and you must learn new concepts, because although you have programmed before (even Java) now you must learn how to do it the “Android’s way”.

After following the video lectures, read and read a lot, I build my first application, which in deed is part of the first assignment for the course. It’s a simple application which reads the device’s battery, and reports if it is charging or discharging, as well as the percentage of charge of the device.

For those interested in try my first application, or just take a look to the code for learninf, here I leave the apk file and the main code.

The code (

Here you can take a look to the code for the application:

package com.lgallardo.batteryreporter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
 protected void onCreate(Bundle savedInstanceState) {
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(, menu);
 return true;
public void getStatus(View view) {
TextView statusValueTextView, chargingValueTextView, levelValueTextView;
 ImageView iconImageView;

 String charging = "";
int level, scale;
 float batteryPct;
// Get resources reference
 Resources res = getResources();
// Get values TextViews
 statusValueTextView = (TextView) findViewById(;
 chargingValueTextView = (TextView) findViewById(;
 levelValueTextView = (TextView) findViewById(;

 // Get ImageView (icon)

 iconImageView = (ImageView) findViewById(;

 // Get battery's status
 IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
 Intent batteryStatus = registerReceiver(null, ifilter);
// Check if the battery is charging or is charged?
 int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
 boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING
 || status == BatteryManager.BATTERY_STATUS_FULL;
// Update UI status
// Update UI charging
 if (isCharging) {
 charging = res.getString(R.string.yes);
// Get charging method
 int chargePlug = batteryStatus.getIntExtra(
 BatteryManager.EXTRA_PLUGGED, -1);
 boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
 // boolean acCharge = chargePlug ==
 // BatteryManager.BATTERY_PLUGGED_AC;
if (usbCharge) {
 charging = charging + " " + res.getString(R.string.usb);
 } else {
 charging = charging + " " + res.getString(;

 } else {
 charging = res.getString(;
// Update UI level
 level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
 scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
 batteryPct = 100 * level / (float) scale;



Debmirror problem: gpgv: Can’t check signature: public key not found


I have a mirror where  Debian and Ubuntu packages are hosted ,so people in the internal network can upgrade their software using this mirror. But the other day I realized it couldn’t sync against the Debian mirror, as described in the article How to build Debian and Ubuntu mirrors using debmirror. When I tried to run the sync script I got an error and it exited with errors.

When running debmirror script, it fails with a error similar to this one:

gpgv: Signature made Wed 17 Jul 2013 04:40:31 PM CST using RSA key ID 473041FA
[GNUPG:] ERRSIG AED4B06F473041FA 1 2 00 1374050431 9
gpgv: Can’t check signature: public key not found
gpgv: Signature made Wed 17 Jul 2013 04:40:31 PM CST using RSA key ID 46925553
[GNUPG:] ERRSIG 8B48AD6246925553 1 2 00 1374050431 9
[GNUPG:] NO_PUBKEY 8B48AD6246925553
gpgv: Can’t check signature: public key not found
Release signature does not verify.


Packages are validated using a key, so we can trust what we are downloading from the source repo and what will installed on our computers. Some repositories have a keyrnig with known keys, and it’s likely that a new key signature was added to the Debian/Ubuntu keyring. This can occur  if there is new distro version, and new keys were added, making our keyring out of date (the new keys are missing).


In order to fix this issue, follow the next steps depending on the distro you are mirroring:


Update the repository and import the new keys:

aptitude update
aptitude safe-upgrade
gpg --keyring /usr/share/keyrings/debian-archive-keyring.gpg  --export | gpg --no-default-keyring --keyring /var/data/keyrings/debian/trustedkeys.gpg --import

Sidenote: If no keys were added, download the latest debian-archive-keyring package from the repositories, extract it and use those keyrings. Example:

dpkg -x debian-archive-keyring_2012.4_all.deb  ~
gpg --keyring ~/usr/share/keyrings/debian-archive-keyring.gpg  --export | gpg --no-default-keyring --keyring /var/data/keyrings/debian/trustedkeys.gpg --import


Download the latest ubuntu-archive-kering package and extrack it,  later use the those keyrings . Example:

dpkg -x ubuntu-keyring_2012.05.19_all.deb ~
gpg --keyring ~/usr/share/keyrings/ubuntu-archive-keyring.gpg --export|gpg --no-default-keyring --keyring /var/data/keyrings/ubuntu/trustedkeys.gpg --import

After this procedure, the sync script will run without problems and it will downloaded the latest updates.

, ,

No Comments

How to install VMWare Tools on Debian 7

VMWare Tools - Debian 7.1

Installing VMWare Tool on Debian 7 is not that different than, for example, installing VirtualBox’s Guest Additions. In essence you have to have the system’s compiling tools, its kernel’s headers, then mount a virtual CD to run the script which will compile the kernel’s modules and reboot the machine.

If you want to have more information about it, here I leave the procedure:

  1. Install the compiling tolls for building the moodules (GCC and stuff):
    aptitude install build-essential
  2. Install the current kernel’s headers:
    # aptitude install linux-headers-$(uname -r)
  3. Mount the CD that content the VMWare utility  (From vSphere Client  you have to choose the Install VMWare Tools option  to have the CD available from the VM)
    # mount /dev/sr0  /mnt/
  4. Copy a the utility in a local folder of the system, and extract it:
    # cp /mnt/VMwareTools-8.6.10-913593.tar.gz /opt/
    # cd /opt/
    # tar xfzv VMwareTools-8.6.10-913593.tar.gz
  5. Finally run the utility script to build the needed kernel’s modules:
    # cd vmware-tools-distrib/
    # ./

The script will ask some questions to build the needed modules, which a show next. I put here just some questions and part of the output. For your particular case, answer accordingly:

Creating a new VMware Tools installer database using the tar4 format.
Installing VMware Tools.
In which directory do you want to install the binary files?
What is the directory that contains the init directories (rc0.d/ to rc6.d/)?
What is the directory that contains the init scripts?
In which directory do you want to install the daemon files?
In which directory do you want to install the library files?
The path "/usr/lib/vmware-tools" does not exist currently. This program is
 going to create it, including needed parent directories. Is this what you want?
In which directory do you want to install the documentation files?
The path "/usr/share/doc/vmware-tools" does not exist currently. This program
 is going to create it, including needed parent directories. Is this what you
 want? [yes]
The installation of VMware Tools 8.6.10 build-913593 for Linux completed
 successfully. You can decide to remove this software from your system at any
 time by invoking the following command: "/usr/bin/".
Before running VMware Tools for the first time, you need to configure it by
 invoking the following command: "/usr/bin/". Do you want
 this program to invoke the command for you now? [yes]
 Making sure services for VMware Tools are stopped.
Stopping VMware Tools services in the virtual machine:
 Guest operating system daemon: done
 Unmounting HGFS shares: done
 Guest filesystem driver: done
 [EXPERIMENTAL] The VMware FileSystem Sync Driver (vmsync) is a new feature that
 creates backups of virtual machines. Please refer to the VMware Knowledge Base
 for more details on this capability. Do you wish to enable this feature?
 Before you can compile modules, you need to have the following installed...
 kernel headers of the running kernel
 Searching for GCC...
 Detected GCC binary at "/usr/bin/gcc-4.6".
 The path "/usr/bin/gcc-4.6" appears to be a valid path to the gcc binary.
 Would you like to change it? [no]
Searching for a valid kernel header path...
 Detected the kernel headers at "/lib/modules/3.2.0-4-amd64/build/include".
 The path "/lib/modules/3.2.0-4-amd64/build/include" appears to be a valid path
 to the 3.2.0-4-amd64 kernel headers.
 Would you like to change it? [no]
The vmblock enables dragging or copying files between host and guest in a
 Fusion or Workstation virtual environment. Do you wish to enable this feature?
 [no] yes
 make: Leaving directory `/tmp/vmware-root/modules/vmblock-only'
No X install found.
Creating a new initrd boot image for the kernel.
 update-initramfs: Generating /boot/initrd.img-3.2.0-4-amd64
 Checking acpi hot plug done
 Starting VMware Tools services in the virtual machine:
 Switching to guest configuration: done
 VM communication interface: done
 VM communication interface socket family: done
 File system sync driver: done
 Guest operating system daemon: done
 The configuration of VMware Tools 8.6.10 build-913593 for Linux for this
 running kernel completed successfully.
You must restart your X session before any mouse or graphics changes take
You can now run VMware Tools by invoking "/usr/bin/vmware-toolbox-cmd" from the
 command line or by invoking "/usr/bin/vmware-toolbox" from the command line
 during an X server session.
To enable advanced X features (e.g., guest resolution fit, drag and drop, and
 file and text copy/paste), you will need to do one (or more) of the following:
 1. Manually start /usr/bin/vmware-user
 2. Log out and log back into your desktop session; and,
 3. Restart your X session.
--the VMware team
Found VMware Tools CDROM mounted at /mnt. Ejecting device /dev/sr0 ...

Then reboot the virtual machine and check the VMWare Tools running, checking the VSphere Client status as shown on the upper image or by checking the status in the virtual machine:

# service vmware-tools status
vmtoolsd is running


No Comments

Installing Raspbmcsusessfully

Raspbmc = Rasberry Pi   XBMC

A friend recommended me this distro for running XBMC which was released by one of the developers of the XBMC project with specific optimizations to run on the Rasberry’s hardware. So I decided to test it and I explain here all have to do to install it, that indeed was a little problematic but successfully at the end.

Raspbmc from the installer

Raspbmc install error

The project’s page recommends to use the installer or Network Image, a python script which practically do the whole installing process, partitioning and doing the initial setup…or at least it tried to, because in my case it didn’t work due to my network connection at home didn’t help at all so I couldn’t download the image using the installer. Therefore I had to install the complete image of Raspbmc.

The complete image of Raspbmc

There’s another option offered on the project’s page which is to download the  whole image of Raspbmc of 235 MB called Standalone Image, but after extract it it sizes 1.4 GB roughly. This was an issue because my SD card’s capacity is  1 GB and I didn’t buy another one as I have a 320 GB hard drive just for the Rasberry Pi. Therefore I came up that I could shrink the image to fix my 1 GB SD card.

Repartitioning the image

In a similar way as explained in How to run Raspberry Pi from a USB hard drive article, I dumped the image into a 8 GB pen drive to be able to extract the /boot and the operating system or system file’s root partition. In order to copy the image to the pen drive you must first extract the image and later extract the image and the dump it as raw, as shown next:

# gunzip raspbmc-final.img.gz
# dd if=raspbmc-final.img of=/dev/sdb

If you check it with gparted you should see something like this:

Rasbmc image

Later using  gparted itself I had to resize the partition /dev/sdb2 to 800 MB roughly, so I could put the /boot de 74 MB as well in my 1 GB SD card.


To extract the /boot partition from the pen drive you can do this:

# dd if=/dev/sdb1 of=raspbmc-final_boot.img

In a similar way extract the file system of 800 MB on the another partition:

# dd if=/dev/sdb1 of=raspbmc-final_fsext4.img

Initial setting

The initial setting it’s done by the installer, which is an script that ask some questions as networking parameters and such. Those values can be modifies later on XBMC with an script added for the Raspbmc:


Disk repartitioning

The installation detected the hard drive automatically but it didn’t let me partition it, in fact it erases everything and creates a unique partition which is mounted into /media withe the partition’s UUID . But I wanted three partitions: one for the operating system (/), other for the memory swapping  (swap) and the remaining space for data (/media/Toshiba320), and the /boot partition which must be in the SD card.

To partion the hard drive I deleted and created the partitions using fdisk. At the end the disk was distributed in this way:


Then I edited the /etc/fstab to reflect the changes:

proc /proc proc defaults 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620 0 0
#/dev/sda2 / ext4 defaults,noatime 0 0
UUID=e7db90716-9911-4fc8-95da-86c463f926a4 / ext4 defaults,noatime 0 0
UUID=70a55bca-9fdb-4073-87f6-c15fd7b351dc none swap sw 0 0
UUID=1ff934a3-f7ce-451f-9a07-0915e174a007 /media/Toshiba320 ext4 defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults,noatime 0 0

And later I edited the file /boot/cmdline.txt to indicate that the operating system will be read from the hard drive instead of the SD card:

dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 noatime quiet rootwait loglevel=1   persistent-logs sdhci-bcm2708.enable_llm=1 dwc_otg.microframe_schedule=1 dwc_otg.fiq_fix_enable=1

Disabling the Firewall

To disable the firewall that comes with a DROP rule by default on the Raspbmc, you have to edit the file /etc/network/if-up.d/secure-rmc, where you have to comment the following line:

iptables -A INPUT -i $IFACE -j DROP

You also can disable the firewall form the setting script of XBMC as show next:

Raspbmc settings

Remote control

I have a keyboard and a mouse connected to the Rasberry Pi but this is not practical, the ideal scenario is to have a remote. As the Rasberry Pi is connected to the WiFI the idea is to use this network  instead of IR or Bluetooh. Therefore I thought in an Android application and mi first choice was XBMC Remote but it seems it has some communication issues that makes XBMC goes crazy ( The Raspbmc version and other for Raspbian behaves the same), but at the end I used another application called Yatse which works properly and it looks better as you can see in the next screenshots I took from my phone:

Yatse XBMC remote  Yatse XBMC remote  Yatse XBMC remote


Comparing XBMC I had tried before on the Rasberry Pi, this version really runs well. It plays movies in several formats (.avi, .mkv, .mp4, etc) smoothly. On the other hand it has Linux inside so it’s my download center with qbittorrent-nox, and I use it for other testing purposes. And this is what XBMC reports as resources consumption:



, ,


100 Linux questions!

LPI CompTIA Linux+

100 Preguntas de Linux

Este cuestionario busca evaluar qué tanto sabes de Linux, además de ayudarte en los exámenes de certificación de Linux existente en el mercado, tales como LPI o CompTIA.

Puedes ir respondiendo cada pregunta, marcar algunas en las que tengas dudas para revisarlas posteriormente, y finalmente terminar con el cuestionario donde se mostrará el resultado obtenido. También puedes revisar las respuestas si haces clic en Comprobar las preguntas para que sepas las preguntas que respondiste correcta e incorrectamente, para que en caso de que te hayas equivocado sepas qué temas debes revisar.


, ,


How to create a ramdisk in Linux


A ramdisk is like a disk partition but running directly from the system’s RAM. All data read and written will be faster, and as drawback all data will be erase when you reboot the system. Some Linux distributions use this kind of file system to avoid killing the media, for instance instead of using a files system on a SD Card you can use a ramdisk.

If you need to create a partition of this type here is explained how to do it.

Creating the ramdisk with mount

To create the ramdisk in /tmp/ramdisk type the following commands:

# mkdir /tmp/ramdisk

# chmod 1777 /tmp/ramdisk

# mount -t tmpfs -o size=8G tmpfs /tmp/ramdisk/

 # df -h

 Filesystem Size Used Avail Use% Mounted on
 /dev/sda5 9.2G 533M 8.2G 6% /
 udev 7.9G 4.0K 7.9G 1% /dev
 tmpfs 3.2G 308K 3.2G 1% /run
 none 5.0M 0 5.0M 0% /run/lock
 none 7.9G 0 7.9G 0% /run/shm
 /dev/sda1 268M 50M 204M 20% /boot
 /dev/sda6 9.2G 552M 8.2G 7% /usr
 /dev/sda7 19G 172M 18G 1% /tmp
 /dev/sda9 490G 560M 464G 1% /var
 /dev/sda8 6.5G 143M 6.0G 3% /usr/local
 tmpfs 8.0G 0 8.0G 0% /tmp/ramdisk

Here you can see that the mount command creates a ramdisk by specifying tmpfs as the file system type, the size is given with the size option, and the mount point (which has all permission and the sticky bit enabled).

Creating the ramdisk from the /etc/fstab

If you want changed to be permanent you must add the following line to the /etc/fstab as shown below:

# RAM disk ramdisk
/tmp/ramdisk tmpfs mode=1777,size=8g

Here the device specified is ramdisk, the mount point is /tmp/ramdisk, the file system type is tmpfs, all permission are set for user, groups and other and the sticky bit is enabled, and the ramidisk’s size is defined by the size option.


No Comments