Yes – I use iTunes to organize and sync my music. But all my music is on my local Windows machine, and I can’t share them (only on AppleTV), so I decided to sync my music to my NAS. There I got Plex and other tools to share my music to whatever device I want. Here’s a short tutorial how I did it.
My iTunes runs on a Windows 8.1 PC and my NAS is based on Ubuntu 14.04 LTS, but I think this tutorial also works with similar OSes.
First check your iTunes settings, that all your media files are organised in one folder. Go to Edit->Settings->Advanced.
Now we install Cygwin on the windows PC. In the package installation window search for ssh and install openssh in the Net section. Again search for rsync and install the package from the Net section.
Now open the cygwin terminal and check if ssh and rsync is installed:
Now create a public/private keypair with openssh
ssh-keygen -t rsa
Just accept the default params and don’t enter a passphrase.
then give the new keyfiles the right Permissions:
chgrp -R HomeUsers ~/.ssh chmod 600 ~/.ssh/id_rsa
Exchange keys with the NAS Linux:
cat ~/.ssh/id_rsa.pub | ssh <linux-user>@<linux-hostname/IP> 'cat >> .ssh/authorized_keys'
Enter the linux-user password, and the check if the exchange was successful with this command:
ssh <linux-user>@<linux-hostname/IP> ls
If this command does not need a password, then the key-exchange was ok.
Next Step: Create a Shell Script which will sync the music to the NAS with just one command:
Create a File called backup.sh and place this inside (Replace username, host and directories!):
#!/bin/bash # Backup the iTunes directory to NAS RSYNC=/usr/bin/rsync $RSYNC -avrz --chmod=a+rwx,g+rwx,o+rwx --delete --log-file=/cygdrive/d/Music/backup.log /cygdrive/d/Music/iTunes/ -e ssh <linux-user>@<linux-hostname/IP>:/media/MUSIC/iTunes/
Now rsync takes care of the sync. Execute the script in a cygwin shell with ./backup.sh and check if everything is working.
That’s nice – but how can I call it from the Windows Explorer?
Create another file call it win-start-backup.bat and insert this:
C:\cygwin64\bin\bash.exe -l -c "/cygdrive/d/Music/backup.sh"
Replace your path to cygwins bash.exe and the path to your backup.sh!
With this script it’s now possible to execute it from the Explorer on Windows.
But what if you want to run this script automatically at defined times?
There are 2 Options:
1. The Cygwin – crontab
For this you need to install cygrunsrv – which allows cygwin to run as a service:
cygrunsrv -I cron -p /usr/sbin/cron -a -D net start cron
2. The Windows Task Scheduler
It’s the Windows way of cron 😉
Open the Task Scheduler with Control Panel->System and Security->Administrative Tools->Task Scheduler
From there create a basic task with the wizard and enter the path to the .bat file.