Automaticly backup you Subsonic-installation

Tutorials, tips and tricks.

Moderator: moderators

Automaticly backup you Subsonic-installation

Postby HerrNilsson » Wed Dec 05, 2012 3:25 pm

Hello

I have a rather large music collection, about 3,5TB. So i do not want to lose all my thumbnails and settings.
I therefore created an automatic backup script i'd like to share if anyone else needs it.

I'm running Ubuntu Server but it runs fine on any Linux machine.
You need a mounted cifs or smb share. You can automatically mount the share every time your server starts by editing the /etc/fstab with:

Code: Select all
sudo nano /etc/fstab


Then add the following at the bottom line, replace **** with username and password and replace //IP_TO_BACKUP_LOCATION/Backupfolder_Subsonic with your backup location.

Code: Select all
//IP_TO_BACKUP_LOCATION/Backupfolder_Subsonic /mnt/backup cifs username=****,password=****


Create the script in /bin/execute/scripts/ with

Code: Select all
sudo nano /bin/execute/scripts/backupsubsonic.sh


Then paste the following rows:
Change the username to your actual username.
This will basically zip your installation and put it in a folder with today's date. If you just want one copy, just replace the "Subsonic $(date +%F)" with "Subsonic"


Code: Select all
tar -zcf /home/username/backup.tgz /var/subsonic
/bin/mkdir /mnt/backup/"Subsonic $(date +%F)"
/bin/cp -r /home/username/backup.tgz /mnt/backup/"Subsonic $(date +%F)"
rm /home/username/backup.tgz


Now to run the script automatically you need do the following:

Code: Select all
sudo crontab -e


Then paste:
This will run every day at 01:01. More information about cron http://en.wikipedia.org/wiki/Cron

Code: Select all
01 01 * * * /bin/sh /bin/execute/scripts/backupsubsonic.sh >/dev/null 2>&1


EDIT: If anyone wants help with the same this on a Windows machine i'd be happy to help.

Hopefully this will help someone out. If i can i'll be happy to answer any questions.
HerrNilsson
 
Posts: 60
Joined: Fri Aug 17, 2012 5:13 am

Re: Automaticly backup you Subsonic-installation

Postby daneren2005 » Wed Dec 05, 2012 4:06 pm

I already have a nightly backup script, but I hadn't thought of throwing Subsonic in the backups. Is the db stored under that directory as well?

PS, I just went the cheater route and did a one line addition:

Code: Select all
tar -zcf /mnt/backup/Subsonic/"$(date +%F)".tgz /var/subsonic


Edit: Changed the line to be better file name
Last edited by daneren2005 on Wed Dec 05, 2012 7:22 pm, edited 2 times in total.
Developer of DSub for Android
daneren2005
 
Posts: 1709
Joined: Fri Jul 06, 2012 7:52 pm

Re: Automaticly backup you Subsonic-installation

Postby HerrNilsson » Wed Dec 05, 2012 4:10 pm

Usually you have the database under the subsonic-folder. So it will be included aswell.
I did that fist. But for me it is much faster to tar it first then move it. :)
HerrNilsson
 
Posts: 60
Joined: Fri Aug 17, 2012 5:13 am

Re: Automaticly backup you Subsonic-installation

Postby daneren2005 » Wed Dec 05, 2012 4:15 pm

Yah it probably would be a better idea to do it that way, I'm just trying to keep an already huge backup script from growing too much. I wonder how well this works on a running subsonic instance. I'm guessing if subsonic is running and changes the db while you are copying it it will be an corrupted db.
Developer of DSub for Android
daneren2005
 
Posts: 1709
Joined: Fri Jul 06, 2012 7:52 pm

Re: Automaticly backup you Subsonic-installation

Postby hakko » Wed Dec 05, 2012 4:29 pm

For those running the MusicCabinet server, I'd like to add that there's a handy utility to also back up your PostgreSQL database. It creates consistent backups even if your database is used concurrently.

Reference: http://www.postgresql.org/docs/9.2/stat ... gdump.html
MusicCabinet developer
hakko
 
Posts: 1416
Joined: Tue Apr 17, 2012 7:05 pm
Location: Sweden

Re: Automaticly backup you Subsonic-installation

Postby HerrNilsson » Wed Dec 05, 2012 4:30 pm

daneren2005 wrote:Yah it probably would be a better idea to do it that way, I'm just trying to keep an already huge backup script from growing too much. I wonder how well this works on a running subsonic instance. I'm guessing if subsonic is running and changes the db while you are copying it it will be an corrupted db.


Well i'm running at night so there's no one editing the database then. I have restore successfully once so it should work.
Otherwise you could just kill the process before then fire it up after.
HerrNilsson
 
Posts: 60
Joined: Fri Aug 17, 2012 5:13 am

Re: Automaticly backup you Subsonic-installation

Postby hakko » Wed Dec 05, 2012 4:32 pm

I guess most people do their scanning at night, which is when the database will get written to. That's when you run the risk of saving an inconsistent state. Daily usage is normally just reads anyway (except updating settings etc).
MusicCabinet developer
hakko
 
Posts: 1416
Joined: Tue Apr 17, 2012 7:05 pm
Location: Sweden

Re: Automaticly backup you Subsonic-installation

Postby daneren2005 » Wed Dec 05, 2012 4:38 pm

Hmm, while it probably won't be an issue I guess I'll just assume that while some of them might fail there should statistically speaking be at least one valid backup in the past week. Now the interesting part is pruning the old backups so you only keep so many of them :D
Developer of DSub for Android
daneren2005
 
Posts: 1709
Joined: Fri Jul 06, 2012 7:52 pm

Re: Automaticly backup you Subsonic-installation

Postby jol » Thu Dec 06, 2012 5:41 pm

daneren2005 wrote:I'm guessing if subsonic is running and changes the db while you are copying it it will be an corrupted db.
I know this thread is about Linux, but on Windows one can use volume shadow copies to ensure consistent backups. Is there no similar mechanism for Linux file systems?
Best regards, jol
Subsonic 4.7 running on Acer H340 with LDAP authentication / Windows Home Server 2011 - Android client (3.5)
jol
 
Posts: 52
Joined: Sat Jan 21, 2012 7:40 pm

Re: Automaticly backup you Subsonic-installation

Postby daneren2005 » Thu Dec 06, 2012 8:12 pm

jol wrote:
daneren2005 wrote:I'm guessing if subsonic is running and changes the db while you are copying it it will be an corrupted db.
I know this thread is about Linux, but on Windows one can use volume shadow copies to ensure consistent backups. Is there no similar mechanism for Linux file systems?
Best regards, jol

The only information on shallow copies I can find is that they are links, which of course linux can do, but has nothing to do with being able to do a transactional copy. Maybe you are calling it by the wrong name? Mind giving an example of how you do this in windows?
Developer of DSub for Android
daneren2005
 
Posts: 1709
Joined: Fri Jul 06, 2012 7:52 pm

Re: Automaticly backup you Subsonic-installation

Postby daneren2005 » Thu Dec 06, 2012 8:17 pm

This is an interesting note I found while doing some googling:

"In rsync, transfers are done to a temporary file, which is cut over atomically, so the transfer either happens in its entirety or not at all"

So maybe there is a benefit of doing a rsync, then zipping that folder, then moving it to wherever you want it, then deleting both the tmp folder and the tmp zip

Edit: I changed my setup to be:

Code: Select all
rsync -tr --delete /var/subsonic /tmp
tar -zcf /tmp/subsonic_backup.tgz /tmp/subsonic
mv /tmp/subsonic_backup.tgz /mnt/backup/Subsonic/"$(date +%F)".tgz
rm -r /tmp/subsonic


I keep getting a warning during the tar process though. Any clue which files it's removing this from and if this means it won't be as simple as doing a drop in backup replacement (ie: need to rename a file)?

Code: Select all
Removing leading '/' from member names
Developer of DSub for Android
daneren2005
 
Posts: 1709
Joined: Fri Jul 06, 2012 7:52 pm

Re: Automaticly backup you Subsonic-installation

Postby jol » Fri Dec 07, 2012 6:10 am

daneren2005 wrote:The only information on shallow copies I can find is that they are links, which of course linux can do, but has nothing to do with being able to do a transactional copy. Maybe you are calling it by the wrong name? Mind giving an example of how you do this in windows?
Not Shallow Copies but Shadow Copy - big difference. Sorry for assuming the term is known. If you are interested I can post my batch file using diskshadow, but it is Windows only of course.
daneren2005 wrote:This is an interesting note I found while doing some googling:

"In rsync, transfers are done to a temporary file, which is cut over atomically, so the transfer either happens in its entirety or not at all"
Imho helps only if the file cannot change while the temorary copy is produced and consistency of files is sufficient (usually not the case with databases using multiple files).
Best regards, jol
Subsonic 4.7 running on Acer H340 with LDAP authentication / Windows Home Server 2011 - Android client (3.5)
jol
 
Posts: 52
Joined: Sat Jan 21, 2012 7:40 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 10 guests