Simple WordPress plugin (include-file)

I may have created one of the simplest possible plugins for WordPress. I also have no doubt that this has probably been created before my multiple other people, but it was easier to create than evaluate the existing options out there. If you just want to download the plugin click here.

This plugin includes the contents of a file from a URL or path into a WordPress page or post using a shortcode. It would look like this in your post:

[include_file url='http://example.org/somefile.txt']

I’ve posted the source code below as it might serve as a good template to someone who wants to create their own plugin.

<?php
/*
Plugin Name: include-file
Plugin URI: http://wordpress.org/extend/plugins/include-file/
Description: Includes the contents of a file at a given url in a post.
Version: 1
Author: Tyler Stafford <tyler.stafford@gmail.com>
Author URI: http://tylerstafford.net
*/

function tsIncludeFile($atts,$content=null,$code="") {
	$content = file_get_contents($atts['url']); 
	if ($content == true) {
		return $content;
	} else {
		return "An error occured retreiving " . $atts['url'];
	}
	return $atts['url'];
}

add_shortcode('include_file','tsIncludeFile');
?>

Updates to my KVM backup script

I’ve been spending quite a bit of time refining the KVM backup script. I’ve added the ability for the script to snapshot the LVM block device and immediately restart the machine. I was also not able to find a way to get Windows guests to shutdown reliably. The guest will shutdown if a user is logged on, and if no user is logged on, but it will not shut down if a user is logged on and the user has locked the workstation. To workaround this I added the “-w” option to shutdown a windows guest using the “net rpc shutdown” command with samba. Check out the project on github.

Super simple automated image based virsh/kvm backup


Warning: file_get_contents(https://raw.github.com/tstafford/Simple-image-based-kvm-virsh-backup-script/master/doBackup.sh): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/tstafford/public_html/wp-content/plugins/include-file/include-file.php on line 12

At my workplace I use KVM as our primary virtualization solution with LVM volumes for each virtual hard disk. I have created a simple script to perform an image based backup of a guest using dd. This could be improved by setting a snapshot while the guest is down and then immediately bringing it back up, however, I use backuppc for file based backup of the data on each machine. So, I don’t feel the need to perform image based backups often enough that I can’t fit them in a normal maintenance period.

The script is posted below and at github

Update: I’ve changed this post so it will always include the latest version of the script from github

An error occured retreiving https://raw.github.com/tstafford/Simple-image-based-kvm-virsh-backup-script/master/doBackup.sh