The Blog

Author: admin

Persistent connect to additional MySQL in a clever way.

Posted on


# create ssh key
ssh-keygen

# copy ssh key to the mysql source server
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] -p 2222

# use this to test ssh connection
ssh [email protected] -p 2222

# here we make persistent connection to the source DB by changing DB port
ssh -fNg -L 3307:127.0.0.1:3306 [email protected] -p 2222

# and here we make the connection!
mysql -h 127.0.0.1 -P 3307 -u root -p some_db_on_source_server

Posted in Uncategorized Leave a comment

Citrix XenServer backup without downtime.

Posted on

Backup running Virtual Machine in XenServer. I am working with Citrix XenServer for many years and managing all XenServers using XenCenter installed on a standalone windows machine. We regularly take backup of VMs manually until today, I always take backups after shutting down the VM. Most of VM owner getting disappointed due to server down for a long time. While searching for the Google I found a better way to back up VMs without shutdown them. It means we can take running VM backups and not downtime occurred.

citrix-image

This tutorial we will help you step by step backup process of running VM. Also here is a shell script which can take all VMs backup or specified VM backup, which we can schedule through crontab as well.

Method 1 – Manual Backup of Running VM

Following steps also can be performed through XenCenter, But Linux lovers love the command line. So find commands to do it.

1.1. Find VMs UUID

Use the following command to get list of UUIDs of all vms along with other details. this UUID will be used in next step

xe vm-list is-control-domain=false is-a-snapshot=false

Sample Output:

uuid ( RO)           : 8ac95696-94f3-83c1-bc89-8bb2603f832b
     name-label ( RW): test-vm
    power-state ( RO): running

As per above output test-vm uuid is “8ac95696-94f3-83c1-bc89-8bb2603f832b“. It can be different in your case.

1.2. Create VMs Snapshot

Now use the following command to create snapshot of vm using uuid found in above step. Make sure you are using correct uuid.

xe vm-snapshot uuid=8ac95696-94f3-83c1-bc89-8bb2603f832b new-name-label=testvmsnapshot

Above command will retrun a UUID of snapshot, Use that UUID to convert snapshot to a vm, so we can export it to file using below command.

xe template-param-set is-a-template=false ha-always-run=false uuid=b15c0531-88a5-98a4-e484-01bc89131561

1.3. Export Snapshot to File

Now we can export created snapshot to .xva file, Which can be easily restored from command line or XenCenter.

xe vm-export vm=b15c0531-88a5-98a4-e484-01bc89131561 filename=vm-backup.xva

1.4. Destroy Snapshot

Finally as we have already taken backup to xva file, so we can destroy created snapshot from xenserver.

xe vm-uninstall uuid=b15c0531-88a5-98a4-e484-01bc89131561 force=true

Method 2 – Using Script for Backup Running VMs

To backup all VMs running on XenServer, we can use following shell script also. This script mounted remote file system exported through NFS. This script works for me perfectly, but it may not for you. So use this script at your own risk.

#!/bin/bash
#
# Written By: Mr Rahul Kumar
# Created date: Jun 14, 2014
# Last Updated: Mar 08, 2017
# Version: 1.2.1
# Visit: https://tecadmin.net/backup-running-virtual-machine-in-xenserver/
#

DATE=`date +%d%b%Y`
XSNAME=`echo $HOSTNAME`
UUIDFILE=/tmp/xen-uuids.txt
NFS_SERVER_IP="192.168.10.100"
MOUNTPOINT=/xenmnt
FILE_LOCATION_ON_NFS="/backup/citrix/vms"

### Create mount point

mkdir -p ${MOUNTPOINT}

### Mounting remote nfs share backup drive

[ ! -d ${MOUNTPOINT} ]  && echo "No mount point found, kindly check"; exit 0
mount -F nfs ${NFS_SERVER_IP}:${FILE_LOCATION_ON_NFS} ${MOUNTPOINT}

BACKUPPATH=${MOUNTPOINT}/${XSNAME}/${DATE}
mkdir -p ${BACKUPPATH}
[ ! -d ${BACKUPPATH} ]  && echo "No backup directory found"; exit 0


# Fetching list UUIDs of all VMs running on XenServer
xe vm-list is-control-domain=false is-a-snapshot=false | grep uuid | cut -d":" -f2 > ${UUIDFILE}

[ ! -f ${UUIDFILE} ] && echo "No UUID list file found"; exit 0

while read VMUUID
do
    VMNAME=`xe vm-list uuid=$VMUUID | grep name-label | cut -d":" -f2 | sed 's/^ *//g'`

    SNAPUUID=`xe vm-snapshot uuid=$VMUUID new-name-label="SNAPSHOT-$VMUUID-$DATE"`

    xe template-param-set is-a-template=false ha-always-run=false uuid=${SNAPUUID}

    xe vm-export vm=${SNAPUUID} filename="$BACKUPPATH/$VMNAME-$DATE.xva"

    xe vm-uninstall uuid=${SNAPUUID} force=true

done < ${UUIDFILE}

umount ${MOUNTPOINT}

Download this script directly from Github.com

Posted in Linux, Virtualization, XenServer 2 Comments

How to mount Amazon’s S3

Posted on

S3FS is FUSE (File System in User Space) based solution to mount an Amazon S3 buckets, We can use system commands with this drive just like as another Hard Disk in system. On s3fs mounted files systems we can simply use cp, mv and ls the basic Unix commands similar to run on locally attached disks.

If you like to access S3 buckets without mounting on system, use s3cmd command line utility to manage s3 buckets. s3cmd is also provides faster speed for data upload and download rather than s3fs. To work with s3cmd use next articles to install s3cmd in Linux systems and Windows systems.
Read More

Posted in Linux Leave a comment

Symfony2 Doctrin2 encode password using prePersist Event Listener

Posted on

Service needs to look like this

services:
    user.listener:
        class: AppBundle\EventListener\UserListener
        arguments: [ "@security.password_encoder" ]
        tags: [ { name: doctrine.event_listener, event: prePersist } ]

Listener should look like that

// AppBundle\EventListener\UserListener.php

namespace AppBundle\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use AppBundle\Entity\User;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

class UserListener
{
    protected $container;

    public function __construct(UserPasswordEncoderInterface $encoder)
    {
        $this->encoder = $encoder;
    }

    public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        $encodedPassword = $this->encoder->encodePassword($entity, $entity->getPassword());
        $entity->setPassword($encodedPassword);
    }
}
Posted in Symfony3 Leave a comment
« Previous PageNext Page »