( I am using Mac OS X ) With Rsnapshot I decided to do this :
1° : when USB HD Partition is found in " /Volumes " open an encrypted DMG file inside that partition
2 ° : start Rsnapshot and backing up from a local directory ( " /Volumes/DATI/UNIVERSITA " ) into encrypted DMG
3° : Close Encrypted DMG
So this is my program :
1° : use 4 different LAUNCHD Pilist for trigger 4 different bash scripts ( containing different rsnapshot commands : hourly vs daily vs weekley vs monthly ) when " BACKUPUNIVERSITA" partition ( inside USB HD ) is founded in directory " /Volumes "
2 ° : each bash script opens the same encrypted DMG ( " riassunti.sparsebundle " ) and starts rsnapshot but with different parameters ( hourly vs daily .. )
3° : when it has finished rsnapshot executes ( " cmd_postexec /Users/ikar0/Library/Scripts/smontaDMG.sh " ) a bash script for closing the DMG and delete mounted point if still present
I have made 4 Launchd " Plists " : for hourly , daily , weekly , monthly rsync snapshots .
But I still have 2 problems :
1° : when I connect the USB drive all the 4 scripts ( hourly , daily , .. ) starts immediately and rsnapshots block itself because PID is locked ( even if I have written a " cron job" with Launchd )
2° : I do not know how to dismount the encrypted DMG and ONLY THEN ( wait command ?? ) , IF the " detach " was successful , remove the directory IF still present avoiding duplicate mount points . ( With a duplicate mount point my scripts cannot start because they do not find the directory with the right name , e.g. they find " Riassunti 1 " and not " Riassunti )
Here is the code :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.rsnapshot.periodic-daily</string>
<key>LowPriorityIO</key>
<true/>
<key>WatchPaths</key>
<array>
<string>/Volumes</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>15</integer>
<key>Hour</key>
<integer>18</integer>
</dict>
<key>Program</key>
<string>/Users/ikar0/Library/Scripts/backupgiornaliero.com</string>
<key>ProgramArguments</key>
<array>
<string>backupgiornaliero.com</string>
</array>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.rsapshot.periodic-hourly</string>
<key>LowPriorityIO</key>
<true/>
<key>WatchPaths</key>
<array>
<string>/Volumes</string>
</array>
<key>StartInterval</key>
<integer>3600</integer>
<key>Program</key>
<string>/Users/ikar0/Library/Scripts/backuporario.com</string>
<key>ProgramArguments</key>
<array>
<string>backuporario.com</string>
</array>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.rsapshot.periodic-monthly</string>
<key>LowPriorityIO</key>
<true/>
<key>WatchPaths</key>
<array>
<string>/Volumes</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>30</integer>
<key>Hour</key>
<integer>16</integer>
<key>Day</key>
<integer>01</integer>
</dict>
<key>Program</key>
<string>/Users/ikar0/Library/Scripts/backupmensile.com</string>
<key>ProgramArguments</key>
<array>
<string>backupmensile.com</string>
</array>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.rsapshot.periodic-weekly</string>
<key>LowPriorityIO</key>
<true/>
<key>WatchPaths</key>
<array>
<string>/Volumes</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>15</integer>
<key>Hour</key>
<integer>13</integer>
<key>Weekday</key>
<integer>7</integer>
</dict>
<key>Program</key>
<string>/Users/ikar0/Library/Scripts/backupsettimanale.com</string>
<key>ProgramArguments</key>
<array>
<string>backupsettimanale.com</string>
</array>
</dict>
</plist>
Here are the 4 scripts :
#!/bin/bash
folderToBackup="/Volumes/DATI/UNIVERSITA"
backupVolume="/Volumes/BCKUNIVERSITA"
backupTo="/Volumes/RIASSUNTI/"
DATI="/Volumes/DATI"
# mounts encrypted DMG
if [ ! -e ${DATI} ]
then echo -n "[*]-- Volume Dati Truecrypt NOT connected - Exiting" | logger exit 0
else
echo -n "[*]-- Volume Dati Truecrypt - Continuing" | logger
if [ ! -e ${backupVolume} ]
then echo -n "[*]-- BackupVolume NOT connected - Exiting" | logger exit 0
else
echo -n "[*]-- BackupVolume Connected - Continuing" | logger
echo -n 4467sg3467 | hdiutil attach -stdinpass /Volumes/BCKUNIVERSITA/riassunti.sparsebundle
sleep 15
rsnapshot daily
fi
fi
exit 0
#!/bin/bash
folderToBackup="/Volumes/DATI/UNIVERSITA"
backupVolume="/Volumes/BCKUNIVERSITA"
backupTo="/Volumes/RIASSUNTI/"
DATI="/Volumes/DATI"
# mounts encrypted DMG
if [ ! -e ${DATI} ]
then echo -n "[*]-- Volume Dati Truecrypt NOT connected - Exiting" | logger exit 0
else
echo -n "[*]-- Volume Dati Truecrypt - Continuing" | logger
if [ ! -e ${backupVolume} ]
then echo -n "[*]-- BackupVolume NOT connected - Exiting" | logger exit 0
else
echo -n "[*]-- BackupVolume Connected - Continuing" | logger
echo -n 4467sg3467 | hdiutil attach -stdinpass /Volumes/BCKUNIVERSITA/riassunti.sparsebundle
sleep 15
rsnapshot monthly
fi
fi
exit 0
#!/bin/bash
folderToBackup="/Volumes/DATI/UNIVERSITA"
backupVolume="/Volumes/BCKUNIVERSITA"
backupTo="/Volumes/RIASSUNTI/"
DATI="/Volumes/DATI"
# mounts encrypted DMG
if [ ! -e ${DATI} ]
then echo -n "[*]-- Volume Dati Truecrypt NOT connected - Exiting" | logger exit 0
else
echo -n "[*]-- Volume Dati Truecrypt - Continuing" | logger
if [ ! -e ${backupVolume} ]
then echo -n "[*]-- BackupVolume NOT connected - Exiting" | logger exit 0
else
echo -n "[*]-- BackupVolume Connected - Continuing" | logger
echo -n 4467sg3467 | hdiutil attach -stdinpass /Volumes/BCKUNIVERSITA/riassunti.sparsebundle
sleep 15
rsnapshot hourly
fi
fi
exit 0
#!/bin/bash
folderToBackup="/Volumes/DATI/UNIVERSITA"
backupVolume="/Volumes/BCKUNIVERSITA"
backupTo="/Volumes/RIASSUNTI/"
DATI="/Volumes/DATI"
# mounts encrypted DMG
if [ ! -e ${DATI} ]
then echo -n "[*]-- Volume Dati Truecrypt NOT connected - Exiting" | logger exit 0
else
echo -n "[*]-- Volume Dati Truecrypt - Continuing" | logger
if [ ! -e ${backupVolume} ]
then echo -n "[*]-- BackupVolume NOT connected - Exiting" | logger exit 0
else
echo -n "[*]-- BackupVolume Connected - Continuing" | logger
echo -n 4467sg3467 | hdiutil attach -stdinpass /Volumes/BCKUNIVERSITA/riassunti.sparsebundle
sleep 15
rsnapshot weekly
fi
fi
exit 0
#!/bin/bash
backupTo="/Volumes/RIASSUNTI/"
# unmonts the encrypted DMG
while [ -e ${DATI} ]
do hdiutil detach $backupTo
wait 5
done
sleep 15
mv ${backupTo} /
exit 0
Thanks for the Help !!
Marco
