Home » HTPC » Automatic backup of XBMC databases, config files, and images on Linux (Ubuntu)
HTPC

Automatic backup of XBMC databases, config files, and images on Linux (Ubuntu)

XBMC is an awesome media center application. I have previously written several posts on it. With all the customizations that I have been doing with my XBMC setup, it became more important than ever to backup my XBMC configuration files. But I wanted a simple and automatic solution. I could not find any addon to do this. After several hours of research I decided to write my own script for it. Described below is a solution that has worked for me whenever I had restore my settings.

In linux, the XBMC data folder is typically stored in the user’s home directory under the name “.xbmc”. Example:

/home/user/.xbmc

Within this folder there are several subfolders containing the following information:

  • Addons and Addon Settings
  • Databases (SQLite Videos and Music)
  • Playlists
  • Thumbnails (Posters, Fanarts, etc.)
  • Settings and Configuration Files

While XBMC offers exporting your library, I have always found that backing up the whole directory is the most convenient and foolproof way. Depending on your media library and addons, the .xbmc folder can range from few MBs to few GBs. If your .xbmc folder becomes huge with unncessary thumbnails, refer to this post on how to clean them.

As in my case, if space is not a limitation then backing up the whole .xbmc directory may be a good solution. In case of need, just restore the whole .xbmc directory and your XBMC will go back to how it was on the day the backup was made. Below is what I wanted to achieve:

  1. Automatic
  2. Simple – set it and forget it
  3. Periodic – every week in my case
  4. Automatically delete backups older than a certain date

Here is the bash script I came up with:

#!/bin/bash
DATE=`date +%Y%m%e-%H%M%S` 
find /home/user/backups/xbmc/ -type d -mtime +30 -exec rm -rf {} ;
mkdir /home/user/backups/xbmc/$DATE
rsync -rgop /home/pivean/.xbmc/ /home/user/backups/xbmc/$DATE/

Save the above script as “xbmcweeklysync.sh” (or whatever) in folder of your choice.

NOTES:
DATE: stores the current date and time as YYYYMMDD-HHMMSS.
find: finds all folders older than 30 days and deletes them. To change the folder age limit, change “-mtime +30” to whatever age that works for you.
mkdir: creates a folder with the name YYYYMMDD-HHMMSS within your backups folder.
rsync: syncs the current .xbmc folder to the folder created above. Read the rsync manual to understand what “-rgop” means or to customize the options further.

Now with the script ready, setup up a cron job to run it automatically every day. I find it easier to setup a cron job through my Webmin interface. Below is a picture to show my setup:

XBMC Backup Weekly Cron Job
XBMC Backup Weekly Cron Job

You can customize the cron job to execute at a frequency you wish (my need was ever week). After having run the above script for couple months month now, this is how my backup folder looks:

XBMC Backups
XBMC Backups

Only the weekly backups within the last 30 days have been retained. There you go. Hope this works for you.

About the author

Anand

Anand is a self-learned computer enthusiast, a part-time blogger, and a Food Scientist by career. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, XBMC, and related HOW-TOs (read more).

Archives

Join the other 110,000 followers