Sunday 2 August 2015

Backing Up Virtual Guests

My virtual guests use LVM for disk storage so we can use the snapshot feature to take live backups.

As these are disk image backups they are large but they are quick - a 10gb disk backup took 5 mins - as I have a huge dedicated backup disk for storing them this isn't a problem.
A note about the backup disk, I've formatted it as ext4 without LVM for maximum compatibility. Should the hardware fail I can pop it into another machine, mount up and go.

Here's an example:

First take a snapshot of the logical volume containing the virtual disk:
lvcreate -s --size=1G -n lv_dns_snap /dev/vg_guests/lv_dns
As the snapshot holds disk updates it needs to be large enough to hold all changes during the lifetime of the snapshot. 1GB is plenty for me. The lvs command will show you how much of the space the snapshot is consuming if you want to tune this.

Next take a copy of the snapshot with dd
dd if=/dev/vg_guests/lv_dns_snap of=/backup/dns-backup.dd bs=1M
Experiment with the block size parameter to see what gives best results for you - 1M worked well for me.

We're done so remove the snapshot
lvremove -f /dev/vg_guests/lv_dns_snap
Whilst we're at it we should also copy the guest xml config file from /etc/libvirt/qemu

Should you need to restore the backup, just shut the guest down and copy the disk image back
dd if=/backup/dns-backup.dd of=/dev/vg_guests/lv_dns

Installing Madsonic on Centos

Some notes on how I ported my Madsonic install from Windows to Centos.

I've put the OS on one disk and my music will live on the other. Set the 2nd disk up and copy my music across first:
pvcreate /dev/vdb1
vgcreate vg_mymusic /dev/vdb1
lvcreate -n lv_mymusic --extents 100%FREE vg_mymusic
mkfs.ext4 /dev/mapper/vg_mymusic-lv_mymusic
Edit fstab & mount to /mymusic
smbclient -L //media1
mount -t cifs //media1/media /mnt -o user=paul
cp -rf /mnt/* /mymusic

I have Madsonic runing on 4040 & 4443 (sssl) so open the firewall
Set FQDN & hostname in hosts or DNS.

Add a user to run it and make sure it can write to the music directory
useradd madsonic
chmod -R 770 /mymusic
chgrp -R madsonic /mymusic
Install & change options in /etc/sysconfig/madsonic
yum localinstall 20141017_madsonic-5.1.5200.rpm
MADSONIC_ARGS="--https-port=4443"
MADSONIC_USER=madsonic
Log into web interface and configure some options:
  • Change admin password
  • Set the media folder
    • Music /mymusic Index 1(all) Music-Artists Music Enabled
  • Scan the media folder
  • Update last.fm - artist cover sync & artist summary sync
  • Disable the guest user
  • I just have these icons available to normal users
    • Home, Artist, Playing, Starred, Genre, Random, Settings, Playlists, Playlists Editor
  • When creating users make sure you check "User is allowed to use last.fm feature" otherwise they won't see artist details.
  • I change the welcome message: 
__Welcome to Paul's Music Library!__
\\ \\
Play at your peril.....
Update the SSL cert by replacing subsonic.keystore in /usr/share/madsonic/madsonic-booter.jar
It's the same file that was used on the Windows version.

It appears that some of my wma files have the album cover art embedded into the audio file(??!!) This confuses ffmpeg when Madsonic attempts to convert them to mp3 to play. This can be fixed by updating the transcode options Madsonic passes to ffmpeg. This forces ffmpeg to transcode the first audio track rather than just the first track (which is the cover art)
  • For the audio->mp3 options change -map 0:0 to -map 0:a:0

Tip: If you're having problems playing some files - this is how I fixed my wma file problem
  • Turn the logging level up to debug (In general options Logfile logging level) to see what options are being passed to ffmpeg. Log file is /var/madsonic/madsonic.log
  • Pass these options manually to ffmpeg with debug logging flag to get extra detail
    • Eg: /var/madsonic/transcode/ffmpeg -i myfile.wma -map 0:0 -b:a 128k -v 0 -f mp3 -loglevel debug /tmp/myoutputfile.mp3