News

Linux Quick backup of current folder

Sometimes you just need a fast backup of the current folder...

To adapt to Godaddy shared hosting SSH access, remove the sudo from the tar command.

!/bin/bash
#
# Simple bash script to compress the current folder structure into a
# tar.gz file in a backup folder under the current user home folder.

#
# Tested on various linux systems.

# Sets the date variable format for zipped file: MM-dd-yy_hh_mm
NOWDATE=`date +%Y-%m-%d_%H%M`

StartAfterPing.cmd

Sometimes you just need to wait...

@echo off
rem #
rem # Written by Ian Willis 2010-10-10
REM Launch an application ONLY if we can ping an address.
REM Loop until we do ping.

set shortcut=c:\Notepad.lnk
set server=www.example.com

:PING
ping %server%
if %errorlevel%==1 (
Echo "Ping failed."

)
if %errorlevel%==0 (
msg %USERNAME% "Ping succeded, Application %shortcut% will start now."
start %shortcut%
goto exit

)

Find folder sizes on Ubuntu

Scenario

I needed to find out the amount of data stored in a group of folders. Each of the folders contains a web site, and I want to track the sites on-disk usage statistics.

Prerequisites

Linux system running bash.

du binary (typically induced in linux base install or busybox.

Tested on Ubuntu 12.

Command

du -shc *

Explanation:
s ..... Summary
h ..... Human Readable. K, M, and G for sizes.
c ..... Summary or Total
* ..... All files or folders in the current directory.

Add SWAP disk on Amazon EC2 Ubuntu servers

Scenario

My Ubuntu web servers were killing processes due to low free memory. I would prefer them to slow down than to kill processes. So I added SWAP disk space that is not setup by default in the EC2 instances.

Prerequisites

Amazon AWS EC2 Ubuntu 11 or 12 instance.

This may work on other Linux versions, but I have only used it on Ubuntu.

Removing old JAVA installs

Scenario

First off, Java.com has a Java applet to do this very thing.
http://java.com/en/download/uninstallapplet.jsp

However, if you need to run this on many computers using a login script, or patch management system, here is my alternative.
It may not be complete, but it removes several versions of java using the command line uninstall method and a little brute force execution.

Batch Move files

Scenario

I needed to move files in batches that would put no more than 600 files in a folder at any time. I wrote the batch file to count the files in the target directory,

Prerequisites

Tested on Windows 2008 R2.

Command line should be compatible with Windows 2000 or newer.

Backup Shell Script for Linux Web Host

Scenario

Backup multiple web sites stored on a Linux server. Sites are stored in a single folder as sub-folders.

I run a web host that is a custom fault tolerant solution on Amazon AWS t1.micro hosts. The primary host should be backed up daily, but a historic backup was necessarily. My goal was to have two weeks of daily backups. The sites databases are backed up separately, so my primary concern was the folder contents.

Clone multiple virtual machines to a different datastore as a backup

Scenario

Clone multiple virtual machines to a different datastore as a backup.

All of my virtual servers, and ONLY virtual servers in a specific folder in vcenter, needed to be cloned to a backup datastore weekly, so I wrote a powershell script to clone them. I then added a Scheduled Task on my vCenter server to execute the script on Saturday evening.

https://github.com/willisiw/ShellScripts/blob/master/vm-bulk-clone.ps1

Hosting Experiment

Case:

I selected a site that I have had in production for some time, but recently upgraded to Drupal 7 & Commerce Kickstart 2.4. The problem was that some of the heavier coded sections of the site would take minutes to load. The front page could take 3-6 seconds to load, and other user pages could take as long or longer. This is a low traffic site.

Task:

Test the site on different platforms.

Method:

I created a new hosting account with my current host provider to give them a fair shot.