rsync like backup to Rackspace Cloud File with duplicity

It seems that there is no much documentation about how to do rsync like backup with duplicty so here it is :

#!/bin/bash
UPLOAD_TO_CONTAINER="backup" #adjust it as you like
export CLOUDFILES_USERNAME=Your Username
export CLOUDFILES_APIKEY=API_KEY_YOU_GOT
export PASSPHRASE=The Passphrase for your encrypted backup
 
duplicity /full/path cf+http://${UPLOAD_TO_CONTAINER}

This should take care to upload the backup files to the backup container. It does that incrementally and detect the changes to your file system to upload. There is much more option for duplicity look at the manpage for more info.

Posted in Rackspace, Scripts | 25 Comments

Upload to Rackspace Cloud files from GNOME nautilus

After seeing this script http://overhrd.com/?p=106 which allow to upload files with the file manager (finder) of MacosX to Rackspace Cloud Files, I have made a nautilus script that doe the same for us Gnome/Unix users.

Available here :

http://github.com/chmouel/nautilus-rackspace-cloud-file/tree/master

Screensho uploading to Rackspace Cloud File form Nautilus

Posted in Programming, Rackspace, Scripts | Leave a comment

python syntax warning in emacs

One of the best feature to have with Emacs when doing python development is to have a real time syntax error/warning check highlighted in your code to avoid many errors or superfluous code.

This code is taken from the brillant Emacswiki python page.

You need to install pyflakes first which should be available on your linux distro by default in a package or for the other OS you may follow the procedure from the pyflakes webpage.

and add this configuration to your .emacs :

(when (load "flymake" t)
(defun flymake-pyflakes-init ()
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name
                      temp-file
                      (file-name-directory buffer-file-name))))
    (list "pyflakes" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
             '("\\.py\\'" flymake-pyflakes-init)))

make sure pyflakes is in your path and enable flymake-mode by default if you like for all python mode :


(add-hook 'python-mode-hook 'my-python-mode-hook)

go by M-x customize flymake as well if you like to customise some variables.

Posted in Emacs, Python | Leave a comment

emacs daemon and Xdefaults

It does not seems that emacs started with –daemon read the .Xdefauls resource it seems that the only way setting it is by the default-frame-alist variable.

I have my setup like this :

(setq default-frame-alist '((font-backend . "xft")
                            (font . "Inconsolata-14")
                            (vertical-scroll-bars)
                            (left-fringe . -1)
                            (right-fringe . -1)
                            (fullscreen . fullboth)
                            (menu-bar-lines . 0)
                            (tool-bar-lines . 0)
                            ))

PS: inconsolata font can be installed from the package ttf-inconsolata

Posted in Emacs | 8 Comments

Network manager and iwl3945 not showing network

So if you have network-manager not detecting wireless networks it is probably because lately the driver need to be set as up to get the thing going.

On my Debian I have added this to make it works :

echo "/sbin/ip link set wlan0 up"|sudo tee /etc/default/NetworkManager

Posted in Debian | Tagged | Leave a comment

Better output from sqlite3 command line

That weird output from sqlite3 command line is annoying you as well ? Just set this up to get something better :

cat < <EOF>~/.sqliterc
.mode "column"
.headers on
.explain on
EOF
Posted in Programming | Leave a comment

Update Emacs/VIM tags with inotify

When you use the tags interface for Emacs or with VIM you have to generate your tag file everytime you have a new class or things get changed.  Would not be cool to have inotify monitoring your project directory and run the etags command to generate it.

With incron you have cron that can watch some portion of the filesystem and generate an action if certain event appears.  So after installed (aptitude/urpmi) it I have configured this incrontab entry :

/home/chmouel/git/myproject IN_CLOSE_WRITE /home/chmouel/update-ctags.sh py $@ $@/$#

The script update-ctags.sh takes 3 argument one is the type of file to update when it’s changed it accept multipe of them if you delimit with a pipe ie: py|inc|php|c and the two others are identifier from incron to give the base directory and the full path which is something you should not have to change.

The update-ctags is simple as follow which could be hacked for your convenience :

#!/bin/bash
 
ACCEPTED_EXTENSION="$(echo $1|sed 's/|/ /g')"
BASE_DIR=$2
FILE_EXT=${3##*.}
 
[[ -z ${FILE_EXT} ]] &amp;&amp; exit
 
processing=
for extension in $ACCEPTED_EXTENSION;do
    [[ $extension == $FILE_EXT ]] &amp;&amp; processing=true
done
 
find ${BASE_DIR} ! -wholename './.git/*'  -a ! -wholename './.svn/*' -a ! -name '*.pyc' -a ! -name '*~' -a ! -name '*#' -print0| xargs -0 etags -o ${BASE_DIR}/TAGS 2&gt;/dev/null &gt;/dev/null
/home/chmouel/git/swift-container IN_CLOSE_WRITE /home/chmouel/updatectags.sh py $@ $@/$#
Posted in Emacs | 3 Comments

Debian Lenny on Dell Optiplex 760

So if you get that shiny new Dell desktop and ACPI spit bunch of message at the install time and the network driver does not get detected you can follow these steps to have it working.

- Continue the install without the network until you reboot to grub.

- Add hpet=disable at the end of the boot kernel parameter and get into the system.

- Download the latest kernel for your architecture on :

http://kernel-archive.buildserver.net/debian-kernel/pool/main/l/linux-2.6/

- Transfer it on a USB key and dpkg -i it.

- Make sure you add the hpet=disable at the kopt option of /boot/grub/menu.lst and launch a update-grub.

- On reboot you should now have the network you can do the standard tasksel to install a Desktop etc….

Posted in Debian | 8 Comments

What type of MySQL table schemas

Since I always forget stuff like this. This is the SQL query to detect mysql table schemas type (thanks to Darren.B) :

SELECT table_name, table_schema, table_type, engine FROM information_schema.tables where table_schema not in ('information_schema', 'mysql');
Posted in MySQL | 1 Comment

Using ProxyCommand with OpenSSH and a Bastion server.

So at work we have to use a bastion host for all our connections to servers to be able to get called PCI compliant. This kind of stuff could be a pain to use when you have to use another host to do RSYNC/SCP or other stuff that need direct transfer to workstation.

Thankfully OpenSSH is very flexible and have multiple options to easy the pain. If you add this to your ~/.ssh/config :

Host bastion
Hostname IP_ADDRESS_OF_BASTION_SERVER
User YOUR_USERNAME
ProxyCommand none
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p

Host *
ProxyCommand ssh -qax bastion ‘nc -w 600 %h %p’

This will allow you to pass all SSH requests to the bastion server.

I have experimented with different options and this seems to be most efficient way. The ControlMaster ControlPath is to speed up the connections by not reopening a tcp socket all the time to the bastion server. This seems to cause problems with the OpenSSH version shipped with some distros (ie: Fedora) so you may want to remove it if you experience problems. For the ProxyCommand there is way to use cat like this :

ProxyCommand ssh bastion ‘exec 3<>/dev/tcp/%h/22;(cat <&3 & );cat >&3′

but the cat processes seems to hang in memory on the bastion server so netcat seems a better option.  I heard that tcpconnect from the tcputils package should make things smoother but I haven’t tried that.

I have other options in my SSH configuration to allow to be less verbose see ssh_config(5) manpage for detailed description of each of these options :

Host *
ForwardAgent yes
GSSAPIAuthentication no
VerifyHostKeyDNS no
StrictHostKeyChecking no
HashKnownHosts no
TCPKeepAlive yes
ServerAliveInterval 600

By the way forgot to mention you would need to have SSH key exchange configured with the bastion server with a SSH agent runing (these days all distros should do that by default) to don’t have to type the password of your username on bastion server.

I have heard there is way to do that on Windows with putty and plink but I haven’t tried that see this post here about it.

Posted in Scripts | 2 Comments