Search This Blog

Thursday 21 December 2017

Mysql Backup Script

#!/bin/sh
now="$(date +'%d_%m_%Y_%H_%M_%S')"
filename="db_bugs_backup_$now".gz
backupfolder="/backups"
fullpathbackupfile="$backupfolder/$filename"
logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt
echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
mysqldump --user=DBUSER  --password=PASSWORD --default-character-set=utf8 bugs | gzip > "$fullpathbackupfile"
echo "mysqldump finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
chown root "$fullpathbackupfile"
chown root "$logfile"
echo "file permission changed" >> "$logfile"
find "$backupfolder" -name db_backup_* -mtime +8 -exec rm {} \;
echo "old files deleted" >> "$logfile"
echo "operation finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
echo "*****************" >> "$logfile"

Mysql Database and user creation

Database creation,
  • create database dbname;
User creation,
  • CREATE USER 'username'@'%' IDENTIFIED BY 'user@123';

Database Permission,

  • GRANT ALL PRIVILEGES ON dbname. * TO 'username'@'%';

Object Rights: SELECT, INSERT, UPDATE, DELETE , EXECUTE


DDL Rights: Create, Alter, References, Index, Create View, Create Routine, Alter Routine, Event,  Drop, Trigger


Other Rights:
 
Grant Options, Create temporary Tables, Lock tables


Thursday 14 December 2017

Libre office installation Steps in Ubuntu

A. Remove bundled LibreOffice

LibreOffice  can be installed alongside older LibreOffice versions, but conflicts may occur.

To remove prior installations of LibreOffice:
sudo apt-get remove libreoffice-core

If you also want to remove LibreOffice configuration files, use the purge switch:
sudo apt-get remove --purge libreoffice-core

B. Install LibreOffice

Step 1 of 3 – Download compressed packages

Download LibreOffice from the official download page:www.libreoffice.org/download/

Select Linux x86 (deb) for 32 bits systems or Linux x64 (deb) for 64 bits systems.

This how-to supposes that the downloaded file (and language packs) is saved in the "Downloads" directory situated in your home directory.

Download as many language packs as you need.

Step 2 of 3 – Extract the .deb packages

The downloaded file is a compressed .tar.gz archive. In case you want to learn more about these extensions: tar, gzip. To extract this juicy archive, open the "Downloads" directory. Look for a file named:

LibreOffice_5.4.0_Linux_x86_deb.tar.gz or
LibreOffice_5.4.0_Linux_x86-64_deb.tar.gz

right-click on it and select "extract here ". Repeat the extraction process for all language packs. The .tar.gz archive(s) can now be deleted.

Step 3 of 3 – Install .deb packages

Open a terminal.
Change the current directory to the location of the .deb packages:
cd ~/Downloads/LibreOffice_5.4.0.x_Linux_x86_deb/DEBS

or for the 64 bits version:
cd ~/Downloads/LibreOffice_5.4.0.x_Linux_x86-64_deb/DEBS

(No need to write everything: use Tab ↹ to autocomplete the command line, or copy and paste with the middle-click mouse button)

Finally, install all .deb packages:
sudo dpkg -i *.deb

In case you're installing language packs, repeat the and steps cd dpkg for each language pack.

You're done! No need to restart, LibreOffice is ready to be used.

If you have problems launching LibreOffice, try out the following command:
libreoffice5.4
or
/opt/libreoffice5.4/program/soffice

If you're installing a development release (Beta) of LO 6.0, you can launch it with the following command:
lodev6.0

C. Uninstall LibreOffice

If you want to remove LibreOffice, use the following command:
sudo apt-get remove libreoffice5.4*

If you want to remove a development (beta) version of LibreOffice, use the following command:
sudo apt-get remove lodev*

Tuesday 12 December 2017

Mounting VMFS with Ubuntu

The vSphere platform is in my opinion the most complete package for the virtualized datacenter. One of my gripes about it is the manipulation of data in the VMFS file system.. its mostly controlled via the vSphere client, and going deep into CLI on the host itself.That isn't a problem when you live only in a vSphere world but sometimes, for debugging or troubleshooting, an extra tool to get the data off of VMFS wouldn't hurt.

Thats where this tip comes in, there are tools out there that you can use on different operating systems to mount the VMFS datastore. For this article we are going to be using Ubuntu 11.04 desktop to mount a VMFS hard drive.

First off, we are going to need the tools, these are called simply VMFS-TOOLS, and luckily we can get it with a simple apt-get

sudo apt-get install vmfs-tools

Now this is a package install, so there are 3 commands included in this package:

vmfs-fuse debugvmfs fsck.vmfs

For this tip we are going to use vmfs-fuse, which is the utility to mount VMFS.

Lets MAN into VMFS-FUSE…

vmfs-fuse VOLUME MOUNTPOINT

Simple enough, now the only problem is that if we look into /dev and ls, we get a lot of permissions for the disk in question:

2011 05 28 1142

Thats right, 8 partitions esxi created, a simple fdisk will give us the readout of which one is the VMFS partition:

2011 05 28 1145

sdb3 it is!

sudo vmfs-fuse /dev/sdb3 /mnt/vmfs

if there is no errors, it should have mounted. Trying to explore the filesystem is not possible, thats because of the funky permissions it gives:

2011 05 28 1148

This removes only a little convienience, because we can still browser by using the paths

sudo ls /mnt/vmfs -lah

2011 05 28 1151

The pure intention of this tip is to copy VMs out of the VMFS file system for archiving or troubleshooting purposes. So we can copy the VM "test vm" to a folder in ubuntu.

Note that when you copy, all thin disks will be converted to Thick, meaning a thin vm of 8GB will take the full 8GB of space on your local file system.

2011 05 28 1137

Reference: http://www.planetvm.net/blog/?p=1592


VMware Snapshot

What is  VMware Snapshot?

  • A VMware snapshot is a copy of the virtual machine's disk file (VMDK) at a given point in time. Snapshots provide a change log for the virtual disk and are used to restore a VM to a particular point in time when a failure or system error occurs. Snapshots alone do not provide Backup.
  •  Any data that was writable on a VM becomes read-only when the snapshot is taken.
  •  VMware administrators can take multiple snapshots of a VM to create multiple possible point-in-time restore points.
  •  When a VM reverts to a snapshot, current disk and memory states are deleted and the snapshot becomes the new parent snapshot for that VM.
  •  The snapshot file cannot exceed the size of the original disk file, and it requires some overhead disk space.
  • Snapshots will grow rapidly with high disk-write activity volume. Most snapshots are deleted within an hour and VMware recommends deleting snapshots within 24 hours. 
  • Snapshot file formats include *–delta.vmdk file, *.vmsd file and *.vmsn file. Administrators create snapshots in VMware vSphere's Snapshot Manager or with the vmware-cmd command-line-utility.
  •  Deleting, or committing, snapshots merges all of the delta files into the VMDK. If delta files remain in the VM's directory after deletion, the snapshot did not delete properly.

VMware recommends the following best practices regarding snapshots:

  • Do not keep a single snapshot for more than 72 hours. While VMware supports up to 32 snapshots in a chain, try to limit chains to three snapshots.
  • Do not rely upon snapshots for I/O intensive VMs with rapid data changes, because significant data inconsistencies will occur when the VM is restored.

ESXi 5.x/6.x software installation in command line

To patch an ESXi 5.x/6.x host from the command line:

 

  1. Patches for VMware products can be obtained from the VMware patch portal. Select ESXi (Embedded and Installable) in the product dropdown and click Search.
  2. Click the Download link below the patch Release Name to download the patch to your system.
  3. Upload the patch to a datastore on your ESXi 5.x/6.x host using the Datastore Browser from vCenter or a direct connection to the ESXi 5.x/6.x host using the vSphere client.Note: VMware recommends creating a new directory on the datastore and uploading the patch file to this directory.
  4. Log into the local Tech Support Mode console of the ESXi 5.x/6.x host. For more information, see Using Tech Support Mode in ESXi 4.1 and ESXi 5.x (1017910).
  5. Migrate or power off the virtual machines running on the host and put the host into maintenance mode. The host can be put into maintenance mode from the command line with:# vim-cmd hostsvc/maintenance_mode_enter
  6. Navigate to the directory on the datastore where the patch file was uploaded to and verify that the file exists:# cd /vmfs/volumes/Datastore/DirectoryName
    # ls
    Where Datastore is the datastore name where the patch file was uploaded to, and DirectoryName is the directory you created on the datastore.
  7. Install or update a patch on the host using these esxcli commands:Notes:
    • To install or update a .zip file, use the -d option. To install or update a .vib file use the -v option.
    • Using the update command is the recommended method for patch application. Using this command applies all of the newer contents in a patch, including all security fixes. Contents of the patch that are a lower revision than the existing packages on the system are not applied.
    • Using the install command overwrites the existing packages in the system with contents of the patch you are installing, including installing new packages and removing old packages. The install command may downgrade packages on the system and should be used with caution. If required, the install command can be used to downgrade a system (only for image profiles) when the –allow-downgrade flag is set.

    Caution: The install method has the possibility of overwriting existing drivers. If you are using 3rd party ESXi images, VMware recommends using the update method to prevent an unbootable state.

    To Install:

    • Using local setup:# esxcli software vib install -d "/vmfs/volumes/Datastore/DirectoryName/PatchName.zip"
    • Install the ZIP file.

      esxcli --server=server_name software vib update --depot=/path_to_vib_ZIP/ZIP_file_name.zip

    • Where PatchName.zip is the name of the patch file you uploaded to the datastore.

      Note: Alternatively, you can use the datastore's UUID instead of the DirectoryName.

      For example:

      # esxcli software vib install -d "/vmfs/volumes/datastore1/patch-directory/ESXi500-201111001.zip"

      or

      # esxcli software vib install -d "/vmfs/volumes/a2bb3e7c-ca10571c-cec6-e5a60cc0e7d0/patch-directory/ESXi500-201111001.zip"

    • Using http setup:# esxcli software vib install -v viburl Where viburl is the URL to the http depot where VIB packages reside.

      For example:

      # esxcli software vib install -v https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/esx/vmw/vib20/tools-light/VMware_locker_tools-light_5.0.0-0.7.515841.vib

    To Update:

    • Using local setup:# esxcli software vib update -d "/vmfs/volumes/Datastore/DirectoryName/PatchName.zip" Where PatchName.zip is the name of the patch file you uploaded to the datastore.

      Note: Alternatively, you can use the datastore's UUID instead of the DirectoryName.

      For example:

      # esxcli software vib update -d "/vmfs/volumes/datastore1/patch-directory/ESXi500-201111001.zip"

      or

      # esxcli software vib update -d "/vmfs/volumes/a2bb3e7c-ca10571c-cec6-e5a60cc0e7d0/patch-directory/ESXi500-201111001.zip"

    • Using http setup:# esxcli software vib update -v viburl Where viburl is the URL to the http depot where VIB packages reside.

      For example:

      # esxcli software vib update -v https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/esx/vmw/vib20/tools-light/VMware_locker_tools-light_5.0.0-0.7.515841.vib

  8. Verify that the VIBs are installed on your ESXi host:# esxcli software vib list For example:

    # esxcli software vib list

    Name              Version                     Vendor Acceptance Level Install Date
    —————– ————————— —— —————- ————
    ata-pata-amd      0.3.10-3vmw.500.0.0.469512  VMware VMwareCertified  2012-05-04
    ata-pata-atiixp   0.4.6-3vmw.500.0.0.469512   VMware VMwareCertified  2012-05-04
    ata-pata-cmd64x   0.2.5-3vmw.500.0.0.469512   VMware VMwareCertified  2012-05-04
    ata-pata-hpt3x2n  0.3.4-3vmw.500.0.0.469512   VMware VMwareCertified  2012-05-04

  9. After the patch has been installed, reboot the ESX host:# reboot
  10. After the host has finished booting, exit maintenance mode and power on the virtual machines:# vim-cmd hostsvc/maintenance_mode_exit