Saturday, 28 May 2011

Xenserver Backup solutions

There are a lot of different backup solutions available to backup your VMs. So I've compiled a comparative list of some of the available solutions, and in my next post I will tell you about the one I chose for my backups.

Generic Backup Solutions:
  • No agent needed, it uses rsync, rsyncd or smb
  • File level deduplication across all backups
  • Incremental and full backup scheduling
  • Easy to setup
  • Web interface
  • Command Line Interface
  • No support for tape drives
  • disk-based data backup and recovery
  • Free and Open Source
  • No downtime
  • Free and Open Source
  • No downtime
  • Support for tape drives and tape libraries
  • Uses agents
  • Web interface
  • wxWidgets interface
  • Command Line Interface
  • can encrypt data in transit
  • supports snapshots via Windows VSS
  • Data backed up by Bacula must be recovered by Bacula
  • user postings online indicate that it can be quite complex to set up
  • Free and Open Source
  • No downtime
  • Free and Open Source
  • can back up Linux, Unix, Mac and Windows clients to tape, disk and storage grids, such as Amazon Simple Storage Service (S3)
  • Write to Multiple Volumes in Parallel
  • Support for tape drives and tape libraries
  • Virtual tapes
  • use of native tools, such as ufsdump, dump and/or GNU tar
  • Ability to read the backup tapes without Amanda
  • Uses agents
  • Commercial version named Zamanda with added features such as:
    • web-based GUI
    • management console
    • one-click restore and reporting application agents (priced additionally) for Microsoft Exchange, SQL Server and SharePoint, and Oracle
    • 24/7 customer support
    • orderly new feature release schedule
  • Commercial Version Pricing (,3):
    • Basic:
      • Server $400
      • Linux, Solaris and Windows Cients $150
      • Windows Clients for desktops and laptops $200
      • Backup to S3 option $250
    • Standard:
      • Server $500
      • Linux, Solaris and Windows Cients $300
      • Windows Clients for desktops and laptops $300
      • Backup to S3 option $500
      • Oracle agent $300
      • Postgres agent $300
      • VMWare vSphere and ESXi client $300
    • Premium:
      • Server $750
      • Linux, Solaris and Windows Cients $450
      • Windows Clients for desktops and laptops $450
      • Backup to S3 option $750
      • Oracle agent $300
      • Postgres agent $450
      • VMWare vSphere and ESXi client $450
Acronis Backup:
  • Uses agents
  • Server runs on Windows
  • Supports Tape drives and tape autoloaders
  • Compress backups to optimize your storage space.
  • Save storage space and time by excluding non-essential files and folders from backups.
  • Store backups into two different locations — backup to a local disk and a copy to a network share.
  • Automatic or manual splitting of backups
  • Bare-metal restore
  • Perform remote restores of your networked machines
  • Restore to dissimilar hardware-optional
  • Convert backup images to virtual machine formats compatible with VMware, Microsoft Hyper-V, Citrix XenServer and Parallels environments.
  • install Agent on unlimited number of virtual machines
  • Automated deletion of outdated backups
  • Backup validation and consolidation by Acronis Storage Node
  • Consolidate incremental and differential backups to save space (Deduplication).
  • Templates for backup rotation schemes
  • Centralized management
  • Reporting and monitoring
  • Command line with scripting support
  • Encrypted network communications
  • Costs 1784€ per license
Xen specific Backup Solutions:
Manual Snapshots:
XenServer supports three types of VM snapshots: regular, quiesced and snapshot with memory. Regular snapshots are crash consistent and can be performed on all VM types. The VM snapshot contains all the storage information and VM configuration, including attached VIFs, allowing them to be exported and restored for backup purposes.

Quiesced snapshots take advantage of the Windows Volume Shadow Copy Service (VSS) to generate application consistent point-in-time snapshots. The VSS framework helps VSS-aware applications like Microsoft Exchange or Microsoft SQL Server to flush data to disk and prepare for the snapshot before it is taken. XenServer supports quiesced snapshots on Windows Server 2003 and Windows Server 2008 for both 32-bit and 64-bit variants. Windows 2000, Windows XP and Windows Vista are not supported.

Snapshot with memory save the VMs state (RAM).This can be useful if you are upgrading or patching software, or want to test a new application, but also want the option to be able to get back to the current, pre-change state (RAM) of the VM. Reverting back to a snapshot with memory, does not require a reboot of the VM.

Backup across multiple external disks:
  • back up to muliple esata hard drive's so if you have a 1.5 tb image and only 2 1tb esata hard drives you can span it between both.
  • This will work with any number of drive’s as long as the total combined disk space is larger then the vm’s you are trying to back up.
  • This also works if you only have one drive
  • The backup will be just a little larger then the used space on the drive, so even if you have a 2tb virtual drive but it is only using 500gb it should fit on a drive with 600gb or more freespace.
  • need to manualy create a list of VMs to backup
Zero-Downtime Limited-Space Backup Script:
  • Currently, Windows servers are not supported, only Linux VMs and the XenServer instance, itself.
  • based on using the python API and command-line LVM snapshots
  • No downtime
  • Free and Open Source
  • Limited space - "Doing built-in snapshots of VM's was not feasible for us. Currently, there is no way to exclude disks in a snapshot (that we have found). A snapshot will take about double the currently used space for a disk on an SR, and this space cannot be reclaimed until the snapshot is deleted and the machine is shutdown to be coalesced. In one of our VMs we have about 8 TB of user drive space, with no extra space on the SRs where the disks are allocated. We don't have enough room, nor do we care about creating a snapshot with the user data since it is already backed up with netbackup. The script allows us to get no-downtime snapshots of the system disks with only requiring a small and temporary amount of extra space on the SRs".
  • The python API is used to gather metadata about the VM, its disks, and its network interfaces. The metadata is written to plain text files. The data from the disks is imaged by doing a dd on the lvm volumes that correspond to the VDIs for the disks.
  • To restore, a new VM is created and given the memory and CPUs settings stored in the metadata. Then the VIF and disks are restored with the stored images being written to the new lvm volumes.
  • The script is still a work in progress
  • Support for Windows will be added
TINABS (This Is Not Another Backup Script):
  • It is based on using the python API and tested under XenServer 5.6 FP1
  • This library allows you to create simple scripts to backup the skeleton of one or more virtual machines.
  • Data disks are not included and they are recreated empty
  • The core of the library is the backup() function which iterates through a list of user supplied virtual machine and:
    • gets a snapshot of the system disk, attach it to a brand new virtual machine created based on the parameters of the current one in the list,
    • recreates any data disks on a shared SR (I preferly use an NFS SR as destination due to the fact thatt “For file-based VHDs, all nodes consume only as much data as has been written, and the leaf node files grow to accommodate data as it is actively written. If a 100GB VDI is allocated for a new VM and an OS is installed, the VDI file will physically be only the size of the OS data that has been written to the disk, plus some minor metadata overhead” as stated in XenServer Administrator's Guide) and attaches them to the backup one,
    • recreates any VIFs of the original virtual machine and attaches them to the backup one,
    • exports the backup virtual machine in .xva format on a local directory,
    • completely deletes the backup virtual machine.
  • The restoring process simply consists in importing the .xva previously created and restoring any data from a backup!
  • Live backup and export of virtual machines.
  • I don't care about creating a snapshot of the entire virtual machine including even any data disks since their data are already backed up with a backup tool.
  • Run from a remote host (even a Windows machine)
  • Provide a simple GUI (WxPython + XRC)
  • By default (if running through the GUI) all pool's virtual machines tagged with the current day of the week (in the format: Mon, Tue, Wed, Thu, Fri, Sat, Sun) are selected for backup.
  • A single virtual machine can be selected as well
NOTE: In some cases useing the following scritps the disk space won't be freed after deleting the snapshots, if that happens follow this instructions: but according to this problem is solved in XenServer 5.6 FP1

XenServer Live Backup Script:

  • runs on windows
  • written in VBScript
  • Requires that XenCenter be installed on Windows machine you run the script from.
  • Beta Stage
Filippo Zanardo's Xenbackup Script:
  • written in Perl
  • skip VMs by adding them to a list
  • Optional use of snapshot: if set to true backup script try to make a snapshot of the vm, else he shutdown the machine, export and power on the machine
  • Mail Notification
  • Optionaly create a subfolder in the store for each backup based on vm name
  • versioning: Set to true to let the script manage to delete the backup older than a certain day or number or hours specified in the $delnumber variable
  • automount: if set to true script try to mount the backupdir specified in mountcommand at start and umount at end, else no action taken and u have to mount dir manually
  • checkspace: if set to true the script check the avaiable space on the backup dir and if less than $spacerequired quit with a message, size is in MB
  • Free and Open Source
  • the author is also working on a web based Xen backup solution (
Andy Burton's VM export script:
  • Backup of the entire machine
  • Fast recovery in case of disaster
  • Free and Open Source
  • No downtime
  • VDI removal – Run in addition to the standard vm-uninstall command to stop snapshotted VMs allocating all your disk space
  • Backup VM selection – Select between all, running, none and specifically set (by VM uuid) virtual machines.
  • Quiesce snapshots – To take advantage of the quiesce snapshot functionality if the VM supports it.
  • There is an improved version on (posted in: this version adds:
    • some cleanup scripts to handle disk remounts, removal of older backup images, and some logic to not back up if the backup drive is not present and mounted
    • A plaintext dump of all the info needed to figure out what used to be connected to what and where it used to live, all the SR, VM, VIF, UUID's etc. are here in a reasonably readable format if needed.
    • A sctipt that unmounts and remounts the backup disk, and then cleans it up so that we only have the last two backups on it. Needs some logic to abort if the drive isn't, or can't be, mounted.
    • A script to back up the metadata of the Xen Pool in a restorable format. Backs up the host machines over to the backup drive as well.
  • Back up all the VM's, Xen hosts, and metadata from a single Xen host, so you only need to set this up on one machine
  • Backup destination can be an NFS share, SMB share, USB disk, flash drive, or anything else you can get mounted up.
Markround Script:
  • Similar to the previous but more complete
  • Backup and retention policy can be configured from XenCenter
  • Ability to use a different SR for the backups
  • Agentless backup for XenServer
  • Comes in 3 versions, free, Standard ($899/XenServer Host) and DR ($1189/XenServer Host)
  • Volume licensing
  • Block-level data deduplication across all VMs backed up
  • Friendly UI
  • Versions each snapshot that is backed up
  • Alike is able to backup any or all of the drives in any VM
  • Jobs can be scheduled daily, weekly, or monthly; may be configured for multiple runs per day
  • Alike can run on 64-bit Windows, can back up any guest OS
  • Backup to Any Common Storage Type
  • Alike can fully automate and schedule Citrix's Coalesce tool, dramatically simplifying the reclaim process.
  • Alike can schedule the export, migration or replication of your VMs, providing simple offsite support.
  • Alike installs nothing on the XenServer host operating system (Dom0), and does not require disk from XenServer Storage Repository (SR).
PHD backup:
  • Block level deduplication
  • No downtime
  • Backups saved as VHD
  • File level recovery Any OS, Any File System
  • Removes the need to deploy and manage a separate physical server, additional software, scripts or agents for backup and recovery of the virtual environment
  • Simple to Deploy & Easy to Use
  • Integrate management for backup and recovery into XenCenter
  • Data is checked both during the backup and restore processes ensuring data integrity. Self-healing is provided by automatically detecting and repairing corrupt data blocks.
  • Multiple Data Streams for Fast Backup and Restore
  • Job Scheduling
  • Supports Tape Backup Solutions
  • Application Consistent Backup using VSS
  • E-mail notification
  • Support for Thin Provisioned Disks
  • Backup Storage Warnings
  • Distributed Virtual Switch Support
  • Supports all Operating Systems supported by XenServer
  • Licence per host
  • we own the licences with an optional annual subscription.
  • 1395$ until the end of the month, regualrly 2000$ per server. with one year suppor included (email and phone suppot, updates and patches)
  • 280$ per host for the annual subscription 11/5 EST working hours
  • Resellers in Portugal
  • 15 day trial

Possibly Related Posts

Thursday, 26 May 2011

xe command list

Here is a list of the most common commands, for more information visit:

Virtual Machines
List of available virtual machines
xe vm-list
Get uuids of all running VMs
xe vm-list is-control-domain=false power-state=running params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"
Force shutdown a virtual machine
xe vm-reset-powerstate uuid=uuid-of-the-VM force=true
Shutdown VM
xe vm-shutdown vm=<uuid>
Suspend VM
xe vm-suspend vm=<uuid>
List all the parameters available on the selected host
xe vm-param-list uuid=1b334f12-66cf-73cc-b0f9-3059519ace27

Set the number of cores with:
xe vm-param-s<wbr/>et platform:c<wbr/>ores-per-soc<wbr/>ket=4 uuid=xxxxx<wbr/>x
Set the number of CPUS at startup:
xe vm-param-s<wbr/>et VCPUs-at-s<wbr/>tartup=8 uuid=xxxxx<wbr/>x
Set the max number of CPUS:
xe vm-param-s<wbr/>et VCPUs-max=<wbr/>8 uuid=xxxxx<wbr/>xx
List hosts
xe host-list
Shutdown host
xe host-shutdown host=<uuid>
Remove Host from Pool
xe host-forget uuid=<toasted_host_uuid>
Get Pool Master UUID
xe pool-list params=master | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"
Eject host from pool
xe pool-eject host-uuid=9712025f-9b98-4c25-81ef-9222993b71f9
Get VMs running on specified host
xe vm-list resident-on=<host uuid=""> is-control-domain=false
Pending tasks:
xe task-list #to view the Pending tasks
xe task-cancel force=true uuid=<UUID> #to cancel a specific task
Last resort:
Lists networks
xe network-list
Lists Physical Network Cards with specified MAC Address
xe pif-list MAC=1c:c1:de:6b:9f:22
Create a new Network
xe network-create name-label=VLAN_DMZ
Assign a network to a Physical Network Card with a VLAN
xe vlan-create network-uuid=329b55d1-0f77-512a-63ed-8b6bcf429e99 pif-uuid=80c1ea1a-4beb-c1ee-f69d-14e3a699587e vlan=205
Export VM or snapshot to XVA
xe vm-export vm=<uuid_or_name> filename=/backup/Ubuntu_backup.xva
Import XVA file
xe vm-import vm=<name> filename=/backup/Ubuntu_backup.xva
Create a snapshot
xe vm-snapshot vm="<vm_name>" new-name-label="snapshot_name"
Convert snapshot to template
xe snapshot-copy uuid=<snapshot_uuid> sr-uuid=<sr_uuid> new-name-description="Description" new-name-label="Template Name"

Possibly Related Posts

Convert VMware to Xen
  • Uninstall vmtools
    • on linux -
    • on windows uninstall from control panel
  • Power off
  • From VSphere export as OVF
  • From XenCenter import OVF

Possibly Related Posts

Remove GRUB from Windows

Put the Windows Install Disk into the drive and boot it up, select your language, select repair, select which partition/instalation to repair, click open Dos (last option on the list), type the following:
bootrec.exe /FixMbr

Possibly Related Posts

Drop all tables from a PostGreSQL DB

Replace dbname with the actual database name:
psql -U dbname -W -t -d dbname -c "SELECT 'DROP TABLE ' || n.nspname || '.' || c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid)" > /tmp/droptablespsql -U dbname -W -d dbname -f /tmp/droptables

Possibly Related Posts

How to generate a list of installed packages and use it to reinstall packages

This can be useful if you want to install a new machine with the exact same software as another one.
You can save your list of packages easily: see "man dpkg" and search for --set-selections and --get-selections.

The basic of it, though is that to save the list of packages:
dpkg --get-selections > package_list
To restore that list on another system:
sudo apt-get install dselect
sudo dselect update
cat package_list | sudo dpkg --set-selections && sudo apt-get dselect-upgrade
Moving across architectures means that there will be some packages unavailable. They will be ignored; for example, ia32-libs will not be installable on a 32-bit system. That selection will be ignored if you're moving from x86-64 to x86.

You call also skip packages that have version numbers in their names like this:
dpkg --get-selections | grep -vP '.*\d\.\d.*' > pkg_list
See also:

Possibly Related Posts

Monday, 23 May 2011

Cisco Aironet SSID with Radius

Here you have a sample configuration:
aaa group server radius rad_eap
server auth-port 1645 acct-port 1646
aaa group server radius rad_acct
server auth-port 1645 acct-port 1646
aaa authentication login eap_methods group rad_eap
dot11 ssid example-ssid
vlan 29
authentication network-eap eap_methods
authentication open eap eap_methods
authentication key-management wpa
accounting rad_acct
interface Dot11Radio0
encryption vlan 1 mode ciphers tkip
ssid example-ssid
radius-server attribute 32 include-in-access-req format %h
radius-server host auth-port 1645 acct-port 1646 key radius-pwd
radius-server host auth-port 1812 acct-port 1813 key radius-pwd
radius-server vsa send accounting

You don't need the radius-server host auth-port 1812 acct-port 1813 key radius-pwd line.
Radius can use 1812 and 1813 or 1645 and 1646. So the rest of the config is refering to 1645 and 1646 in my example. If your radius server uses 1812 and 1813 you will also need to change the previous lines in the aaa group commands and then ditch the 1645 and 1646 references.

NOTE: If the AP is not sending the ssid information to the radius server try adding this to your AP configuration:
radius-server vsa send

Possibly Related Posts

Delete files older than... in windows

You can use robocopy:
ROBOCOPY C:\work C:\trash /move /minage:14
or xcopy
xcopy *.* /d:04-12-2006 C:\trash
and at the end:
rmdir /s /q C:\trash

Possibly Related Posts

Test Zabbix agent via telnet

From your server telnet to the agent... telnet host 10050

then type in a key to monitor such as the following
type the key on one line and press enter after. If your session gets closed without showing anything then it's likely a misconfiguration in your agent(d).conf file. Otherwise you should see a number.

Possibly Related Posts

Defunct Zabbix_Server Processes

Some times Zabbix stops collecting data and all zabbix_server processes are defunct.

Restarting the Zabbix server doesn't fix the defunct processes. According to the manual page ( on the server config, we can set CacheSize to anywhere between 128K and 1G, the default being 8M. We set it to 32M, and restart the server. Now it's running again. Allegedly, in order to set it any higher, it is necessary to first adjust some kernel parameters with sysctl, like this:
sysctl -w kernel.shmmax=536870912
Or, according to thread 61016 on the Zabbix forum:
Spesific for FreeBSD machine:

Possibly Related Posts

Sunday, 22 May 2011

Install a monitoring Zabbix Server

Install the packages:
aptitude install zabbix-server-mysql zabbix-frontend-php
Set the php time zone:
vi /etc/php5/apache2/php.ini
  • search for date.timezone and set it to "Europe/Lisbon"
  • set "mbstring.func_overload" to 2
  • set post_max_size to 16M
  • set max_execution_time to 300
Restart apache
/etc/init.d/apache2 restart
SNMP Builder is a very useful add-on for Zabbix to help you to build custom SNMP based tamplates, to install-it follow the instructions on the following link:

Look for CISCO MIBs here ->

goto http://<ip_address>/zabbix

Log in using:


Setup Auto Discovery:

Template Linux:
there are several items in the Linux template that are not useful fore every server so I disable the following items and enable them only when needed:
  • Email (SMTP) server is running
  • FTP server is running
  • IMAP server is running
  • News (NNTP) server is running
  • Number of running processes zabbix_server
  • Number of running processes inetd
  • Number of running processes mysqld
  • POP3 server is running
Monitor Apache:

The Debian installation uses apache2 as the Apache process, so if you have a Debian based server farm, you should change your Number of running processes apache item to apache2. The SuSE apache process is named httpd2-prefork, so change the item, if needed. Maybe you need to clone the item, if this is the only server of this type.

Monitor SQUID from Zabbix:

However I had to configure the zabbix_agentd.conf a little bit differently:
# Squid
UserParameter=squid.http_requests,squidclient -h -p 80 mgr:info|grep 'Number of HTTP requests received:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.clients,squidclient -h -p 80 mgr:info|grep 'Number of clients accessing cache:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.icp_received,squidclient -h -p 80 mgr:info|grep 'Number of ICP messages received:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.icp_sent,squidclient -h -p 80 mgr:info|grep 'Number of ICP messages sent:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.icp_queued,squidclient -h -p 80 mgr:info|grep 'Number of queued ICP replies:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.htcp_received,squidclient -h -p 80 mgr:info|grep 'Number of HTCP messages received:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.htcp_sent,squidclient -h -p 80 mgr:info|grep 'Number of HTCP messages sent:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.req_fail_ratio,squidclient -h -p 80 mgr:info|grep 'Request failure ratio:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.avg_http_req_per_min,squidclient -h -p 80 mgr:info|grep 'Average HTTP requests per minute since start:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.avg_icp_msg_per_min,squidclient -h -p 80 mgr:info|grep 'Average ICP messages per minute since start:'|cut -d':' -f2| tr -d ' \t'
UserParameter=squid.request_hit_ratio,squidclient -h -p 80 mgr:info|grep 'Hits as % of all requests:'|cut -d':' -f3|cut -d',' -f1|tr -d ' %'
UserParameter=squid.byte_hit_ratio,squidclient -h -p 80 mgr:info|grep 'Hits as % of bytes sent:'|cut -d':' -f3|cut -d',' -f1|tr -d ' %'
UserParameter=squid.request_mem_hit_ratio,squidclient -h -p 80 mgr:info|grep 'Memory hits as % of hit requests:'|cut -d':' -f3|cut -d',' -f1|tr -d ' %'
UserParameter=squid.request_disk_hit_ratio,squidclient -h -p 80 mgr:info|grep 'Disk hits as % of hit requests:'|cut -d':' -f3|cut -d',' -f1|tr -d ' %'
UserParameter=squid.servicetime_httpreq,squidclient -h -p 80 mgr:info|grep 'HTTP Requests (All):'|cut -d':' -f2|tr -s ' '|awk '{print $1}'
UserParameter=squid.process_mem,squidclient -h -p 80 mgr:info|grep 'Process Data Segment Size via sbrk'|cut -d':' -f2|awk '{print $1}'
UserParameter=squid.cpu_usage,squidclient -h -p 80 mgr:info|grep 'CPU Usage:'|cut -d':' -f2|tr -d '%'|tr -d ' \t'
UserParameter=squid.cache_size_disk,squidclient -h -p 80 mgr:info|grep 'Storage Swap size:'|cut -d':' -f2|awk '{print $1}'
UserParameter=squid.cache_size_mem,squidclient -h -p 80 mgr:info|grep 'Storage Mem size:'|cut -d':' -f2|awk '{print $1}'
UserParameter=squid.mean_obj_size,squidclient -h -p 80 mgr:info|grep 'Mean Object Size:'|cut -d':' -f2|awk '{print $1}'
UserParameter=squid.filedescr_max,squidclient -h -p 80 mgr:info|grep 'Maximum number of file descriptors:'|cut -d':' -f2|awk '{print $1}'
UserParameter=squid.filedescr_avail,squidclient -h -p 80 mgr:info|grep 'Available number of file descriptors:'|cut -d':' -f2|awk '{print $1}'
Monitor Postfix from Zabbix:

but use the script from

Download Zabbix SNMP template generator:
This is a very useful script to automatically generate templates for your network equipment.

Create calculated Items:[]=calculated#calculated_items

Advanced parcing of SNMP Values:

Install zabbix linux clients:
sudo aptitude install zabbix-agent
sudo dpkg-reconfigure zabbix-agent
Input the zabbix server IP address
Now edit the agent conf file:
vi /etc/zabbix/zabbix-agentd.conf
and change the hostname to the correct one

Restat the agent:
sudo /etc/init.d/zabbix-agent restart
For windows get the installer from: or from

Please check my posts about Zabbix Performance:
Simple zabbix tunning tips
Performance tuning mysql for zabbix

Possibly Related Posts

Comment multiple lines in VI

Instead of counting lines ( using: .,+N ) one could also use a search ( .,/WORDONTHELASTLINE/ ),

this is line 1
this is line 2
this is line three
this is line 4
could be commented by putting the cursor on line 1 and using
:.,/three/ s/^/#/g

Possibly Related Posts

Vi: Search and Replace

Change to normal mode with <ESC>.

Search (Wraped around at end of file):

Search STRING forward :

Search STRING backward:

Repeat search:

Repeat search in opposite direction:

Replace: Same as with sed, Replace OLD with NEW:

First occurrence on current line:

Globally (all) on current line:

Between two lines #,#:

Every occurrence in file (global):

Possibly Related Posts

Oracle XE on Ubuntu

Oracle provides a debian repository at, containing only Oracle 10g Express Edition (XE) packages.
To see these packages, add this line to /etc/apt/sources.list file:
deb unstable main non-free
Next, you will need to add the GPG key.
wget -O- | sudo apt-key add -
As root, type:
apt-get update
To install the XE database server, apt-get 'oracle-xe-universal' or 'oracle-xe' (Western European support only).
apt-get install oracle-xe-universal oracle-xe-client
Don't forget to add the hostname to the /etc/hosts file

As root, type:
/etc/init.d/oracle-xe configure
Change the listner conf:

Create user:
Change into the oracle user and setup the environment:
su oracle
export PATH
Connect to the database:
sqlplus sys as sysdba
And actually create the user:
Change the user's permissions:
Adjust the user's quota:
Start Oracle server in UNIX

Type the following command, enter:
$ su - oracle
Now use lsnrctl command to start service (usually located at /home/oracle/oracle/product/10.2.0/db_1/bin directory):
$ lsnrctl start
Next start database:
$ dbstart
Stop Oracle service in UNIX

To stop Oracle servuice type following two commands:
$ lsnrctl stop
$ dbshut

HTTP Interface

Now for creating users / schema / ... you have a nice http interface to do it :http://localhost:8080/apex/

If you want to access this remotely, you may need to use a SSH port forwarding:
ssh -L 8080:localhost:8080 user@IP_of_your_server
It is also possible to use the administration console remotely, even if it's not recommended for security reasons (better using SSH port forwarding as previously said):
sqlplus sys as sysdba

Possibly Related Posts

Passwordless SSH

Setting up the keys on the local machine
Create keys of all sorts, so it will always work (some old computers only serve ssh1):
ssh-keygen -t rsa
ssh-keygen -t rsa1
Leave the default filename asked (press enter). Don't enter a password. You only need to run this once. It will then work for all your connections!

If the rsa first line doesn't work, you can try this (but don't use this one unless rsa doesn't work - RSA, by default, is twice as strong as DSA):
ssh-keygen -t dsa
Agree to the default names but give them passwords when you do this. I???d give each key the same password for ease of use.

Setup the remote host to accept the connections without passwords from the local machine
Before doing this, please make sure you make some SSH connection to create the .ssh directory and file structure.
scp ~/.ssh/
ssh 'cat ~/.ssh/ >> ~/.ssh/authorized_keys2'
ssh 'rm ~/.ssh/'
Then authorise your keys for all systems that share your home directory (on the remote host):
cd ~/.ssh
cat *.pub >> authorized_keys
Now, it should work! Try to SSH to the remote machine and check if it asks you for a password...


If any of the files (or directories leading up to the files) have permissions set too loose, the connection will fail. Permission errors may be logged on the server side by the sshd(8) daemon.

Authentication refused: bad ownership or modes for directory ???

In most cases, potential permission problems can be solved by restricting down access to the SSH configuration files. Permission changes to the home directory might be needed, though restricted rights may break other things, such as a webserver's access to ~/public_html, for example.
server$ chmod go-w ~/
server$ chmod 700 ~/.ssh
server$ chmod 600 ~/.ssh/authorized_keys
You can also use this script to automate the Key transfer:

On the Source
Create the file with the following contents:
echo "Syntax: $0 remote_account destination_ip"
ssh $1@$2 'mkdir -p ~/.ssh'
scp ~/.ssh/ $1@$2:~/.ssh/
ssh $1@$2 'cat ~/.ssh/ >> ~/.ssh/authorized_keys2'
ssh $1@$2 'cat ~/.ssh/*.pub >> ~/.ssh/authorized_keys'
ssh $1@$2 'rm ~/.ssh/'
Now run
chmod +x

Possibly Related Posts

Squid Client

Squid Client is a very useful tool to monitor a Squid proxy server, you can use it to help you tune up your cache server.

To get general info about the cache:
squidclient -h <server_ip> -p <squid_port> mgr:info
Check Squid pool:
squidclient -h <server_ip> -p <squid_port> mgr:delay
List Clients:
squidclient -h <server_ip> -p <squid_port> mgr:client_list

Possibly Related Posts

HOWTO Remove comments and blank lines in a config file

egrep -v '^$|^\s*#' configfile
^$ - matches the empty lines
^\s*# - matches lines that start with a #

Possibly Related Posts

Delete lines from file2 beginning with file1

A very simple script:
while read WORD
cmd="$cmd -e /^$WORD,/d"
done < file1
sed $cmd < file2 > file3

Possibly Related Posts

PostgreSQL dump and restore

Backup one database:
pg_dump dbname > outfile
or if you want to clean (drop) schema prior to create (drop databases prior to create):
pg_dump -c dbname > outfile 
Restore one database:
psql dbname < infile
Copy database from one host to another:
pg_dump -h host1 dbname | psql -h host2 dbname
Backup all databases:
pg_dumpall > outfile
Note: you can add the --clean option to drop tables before restoring

Restore all databases:
psql -f infile postgres

Possibly Related Posts

PostgreSql - Create user and DB

To create a user:
createuser -d -P -l username
To create a database:
createdb -W -U username dbname
Test with:
psql -d dbname -U username -W
if you get an error message saying "psql: FATAL: Ident authentication failed for user 'username'"
vi /etc/postgresql/8.4/main/pg_hba.conf
By default Postgresql uses IDENT-based authentication. All you have to do is allow username and password based authentication for your network or webserver. IDENT will never allow you to login via -U and -W options. Append following to allow login via localhost only:
local all all trust
host all all trust
for any host:
local all all trust
host all all trust
You will have to restart the service
/etc/init.d/postgresql-8.4 restart
NOTE: If you want the server to prompt for a password instead of trust use password but this method sends the password in cleartext over the network.

Possibly Related Posts

MySQL Create DB

Crete a DB | schema:
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [create_specification] ...
[DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name
Create Uer:
CREATE USER 'username'@'%' IDENTIFIED BY 'mypass';
GRANT ALL ON db_name.* TO username @'%' IDENTIFIED BY 'mypass';
Note: Users 'User'@'%' and 'User'@'localhost' are not the same.

Possibly Related Posts

Saturday, 21 May 2011

MySQL Dump and Restore


All databases:
mysqldump --user=XXXXXXXX --password=XXXXXXX -A > /PATH/TO/DUMPFILE.SQL
Just some DB:
mysqldump --user=XXXXXXXX --password=XXXXXXX --databases DB_NAME1 DB_NAME2 DB_NAME3 > /PATH/TO/DUMPFILE.SQL
Just some tables:
mysqldump --user=XXXXXXXX --password=XXXXXXXX --databases DB_NAME --tables TABLE_NAME > /PATH/TO/DUMPFILE.SQL

NOTE: if you get and error saying "(...)when using LOCK TABLES" append this to the dump command:
mysql --verbose --user=XXXXXXXX --password=XXXXXXXX DB_NAME < /PATH/TO/DUMPFILE.SQL
GRANT ALL ON db_base.* TO db_user @'%' IDENTIFIED BY 'db_passwd';
Change User password:
$ mysql -u root -p
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='tom';

Possibly Related Posts

Find and replace in MySQL

MySQL database has a handy and simple string function REPLACE() that allows table data with the matching string (from_string) to be replaced by a new string (to_string). This is useful if there is need to search and replace a text string which affects many records or rows, such as change of company name, postcode, URL or spelling mistake.

The syntax of REPLACE is REPLACE(text_string, from_string, to_string)

MySQL reference describes REPLACE as function that returns the string text_string with all occurrences of the string from_string replaced by the string to_string, where matching is case-sensitive when searching for from_string, text_string can be retrieved from the a field in the database table too. Most SQL command can be REPLACE() function, especially SELECT and UPDATE manipulation statement.

For example:
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’); 
update client_table set company_name = replace(company_name, ‘Old Company’, ‘New Company’);

The above statement will replace all instances of ‘Old Company’ to ‘New Company’ in the field of company_name of client_table table.

Another example:

SELECT REPLACE(‘’, ‘w’, ‘Ww’);

Above statement will return ‘’ as result.

Possibly Related Posts

Recover MySQL root Password

Here are the commands you need to type for each step (login as the root user or use sudo):

Step # 1 : Stop mysql service
# /etc/init.d/mysql stop
Stopping MySQL database server: mysqld.
Step # 2: Start to MySQL server w/o password:
# mysqld_safe --skip-grant-tables &
The output should be something like:
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
Step # 3: Connect to mysql server using mysql client:
# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
Step # 4: Setup new MySQL root user password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Step # 5: Stop MySQL Server:
# /etc/init.d/mysql stop
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/
mysqld_safe[6186]: ended
[1]+ Done mysqld_safe --skip-grant-tables
Step # 6: Start MySQL server and test it
# /etc/init.d/mysql start
# mysql -u root -p

Possibly Related Posts

Postfix Queue Management

Again some very useful one liners but this time to manage the Postfix mail queue.

Release messages from hold
mailq | awk '{if($1 ~ /[A-F0-9]+!$/) {gsub(/!/, "", $1); print($1); system(sprintf("postsuper -H%s", $1)); } }'
postqueue -f 
Requeue hold messages to force delivery
mailq | awk '{if($1 ~ /[A-F0-9]+!$/) {gsub(/!/, "", $1); print($1); system(sprintf("postsuper -H%s", $1)); } }' 
Flush the queue
postqueue -f
Clean all MAILER-DAEMON error messages 
Normal Messages
mailq | tail +2 | awk '{ if ($7 == "MAILER-DAEMON") print $1 } ' | postsuper -d -
for me mailq returns the message id with a trailing ! so I use:
mailq | awk '{ if ($7 == "MAILER-DAEMON") print substr ($1, 1, length($1)-1) } ' | postsuper -d -

Messages with errors
mailq | grep MAILER-DAEMON |  sed -e 's/!$//' | cut -d " " -f 1 | postsuper -d -
mailq | tail +2 | awk '{ if ($7 == "MAILER-DAEMON") print $1 } ' | sed -e 's/!$//' | postsuper -d -
If you want to delete messages with the ! sign on the end, use
mailq | tail +2 | awk '{ if ($7 == "MAILER-DAEMON") print $1 } ' | cut -d! -f 1 | postsuper -d -
NOTE: Sometimes, you may need to omit the:
tail +2

Possibly Related Posts

Reading message content on postfix queue

Get the id of the message by

mailq | grep "search something"


postcat -q MESSAGE_ID 

Possibly Related Posts

One liners

I love one liners, here is a list of a few useful one line scripts

Get all the lines which are not common to the two files.

diff file1 file2 | sed '/^[0-9][0-9]*/d; s/^. //; /^---$/d' > file3

Rename multiple files:
(this removes the extension of all .conf files in current dir)
mmv '*.conf' '#1'
Search and Replace in Multiple Files in perl(easy as PIE)
perl -p -i -e 's/<oldword>/<newword>/g' *
Remove comments and blank lines from file
egrep -v '^$|^\s*#' configfile
Find out which process is using up your memory using ps, awk, sort
ps aux | awk '{if ($5 != 0 ) print $2,$5,$6,$11}' | sort -k2n
ps ­eo user,pid,pcpu,cmd,args ­­sort ­pcpu | head ­n20
Find out Top 10 Largest File or Directory Using du, sort and head
du -sk /var/log/* | sort -r -n | head -10
Find out Top 10 Most Used Commands.
cat ~/.bash_history | tr "\|\;" "\n" | sed -e "s/^ //g" | cut -d " " -f 1 | sort | uniq -c | sort -n | tail -n 15
Search mail logs for log in attempts
for i in `ls /var/spool/mail`; do echo $i; cat /var/log/maillog* | grep -i LOGIN| grep $i | wc -l; done
for i in `ls /var/spool/mail`; do echo $i; cat /var/log/maillog* | grep -i LOGIN| grep "authid="$i | wc -­l; done
Check Top Connections
PORT=110;netstat ­antp | awk '$4 ~ /:'$PORT'$/ {c++;print $5|"cut ­f1 ­d:|sort |uniq ­c| sort ­n"} END {print c}

Possibly Related Posts

Friday, 20 May 2011

First Post

With this blog I intend to share the notes that I've been gathering in my Tomboy.
This notes are the fruit of hours searching the web for similar problems to mine. So I'm now posting them hopping that they will help others.

The notes I'll post will give examples or recipes of how to do various things, which I usually find most helpful.

Possibly Related Posts