|
|
How to access Time Machine files from Linux
I made a little script to automise the retrivieng of files. Hope this helps.
#!/bin/bash
#set -e
#
#---------------------------------------------------------
# Simple script to get files in an Apple Time Machine (TM) archive. Inspired by http://hints.macworld.com/article.php?story=20080623213342356
#
# You need to have rsync installed : sudo aptitude install rsync
#
# You need to run this script with the full path, ie. /usr/local/bin/tmrestore {arguments...} not ./tmrestore
#
# You need to run this script as root, running it in a real shell (not sudo script). Try "sudo su -" then invoke the script.
#
# Use tab completion to fill the arguments ie. /media/Time\ Machine\ Mount\ Point and not "/media/Time Machine Mount Point" (with double quotes). This must be also for the last argument if spaces are present.
#
# Exemple invocation :
#
# /usr/local/bin/tmrestore /media/Time\ Machine\ Mount\ Point/.HFS+\ Private\ Directory\ Data^M/ /TM\ Restore/My\ Files /media/Time\ Machine\ Mount\ Point/Backups.backupdb/iMac/Latest/Macintosh\ HD/Users/john/Desktop Desktop
#
# where :
# - /media/Time\ Machine\ Mount\ Point/.HFS+\ Private\ Directory\ Data^M/ is the path to the Time Machine hidden directory
# - /TM\ Restore/My\ Files is the path to where you want to restore your files/dirs
# - /media/Time\ Machine\ Mount\ Point/Backups.backupdb/iMac/Latest/Macintosh\ HD/Users/john/Desktop is the path in the Time Machine archive of the file/directory you want to restore
# - Desktop is the name of the directory that will be created in the path to where you want to restore your files/dirs
#
# THIS SCRIPT COMES WITH WARRANTY! (and is GPL)
#
# Feel free to improve it (adding comments, for exemple ;)
#---------------------------------------------------------
DEBUG=1
if [ $DEBUG -eq 1 ]
then
echo ""
echo "invoking $0 with arguments :"
# note : if you copy/paste this code, you must replace ^M with the carriage return caracter. This is done, in vim, by, in edition mode (i), typing CtrlV, then the Enter key :
HFS=`echo $1 | sed s/"^M"//g`
DIR=`echo $3 | sed s/"^M"//g`
echo "\$HFS : $HFS"
echo "\$REST : $2"
echo "\$DIR : $DIR"
echo "\$DIRNAME : $4"
fi
IFS="
"
usage()
{
echo "Usage: `basename $0` [Path to .HFS hidden directory] [Path where to restore] [Path to directory to restore] [Name of the directory to restore]"
}
HFS="$1"
REST="$2"
DIR="$3"
DIRNAME="$4"
[ $# -ne 4 ] &! [ -d "$HFS" ] &[ "$REST" == "/" ] &[ "$REST" == "$HOME" ] &[ $DEBUG -eq 1 ] && echo ""
[ $DEBUG -eq 1 ] && echo "mkdir -p "$REST""
mkdir -p "$REST"
if [ -f "$DIR" ]
then
INODE=`ls -l "$DIR" | cut -d " " -f2`
SIZE=`ls -s "$DIR" | cut -d " " -f 1`
if [ $INODE -gt 100 ] && [ $SIZE -eq 0 ]
then
[ $DEBUG -eq 1 ] && echo "$DIR is a specal TM dir, self invoking :"
$0 "$HFS" "$REST/$DIRNAME" "$HFS/dir_$INODE" "`basename -- $DIR`"
[ $? -ne 0 ] && exit 1
else
[ $DEBUG -eq 1 ] && echo rsync -avP -- "$DIR" "$REST"
rsync -avP -- "$DIR" "$REST"
fi
else
cd "$DIR"
for i in `ls -a .`
do
FILE="`basename -- "$i"`"
[ "$FILE" == "." ] && continue
[ "$FILE" == ".." ] && continue
[ "$FILE" == ".DS_Store" ] && continue
# please add file or dir you don't want to restore :
[ "$FILE" == "backup dd externe" ] && continue
[ "$FILE" == "Flash Player" ] && continue
if [ -f "$FILE" ]
then
INODE=`ls -l "$FILE" | cut -d " " -f2`
SIZE=`ls -s "$FILE" | cut -d " " -f 1`
if [ $INODE -gt 100 ] && [ $SIZE -eq 0 ]
then
[ $DEBUG -eq 1 ] && echo "$FILE is a specal TM dir, self invoking :"
$0 "$HFS" "$REST/$FILE" "$HFS/dir_$INODE" "$FILE"
[ $? -ne 0 ] && exit 1
else
[ $DEBUG -eq 1 ] && echo rsync -avP -- "$FILE" "$REST"
rsync -avP -- "$FILE" "$REST"
fi
else
$0 "$HFS" "$REST/$FILE" "$DIR/$FILE" "$FILE"
[ $? -ne 0 ] && exit 1
fi
done
fi
exit 0
How to access Time Machine files from Linux
Awesome script! Thank you very much. It worked perfectly except it keep repeatedly hanging on a corrupt file; I just had to hid Ctrl-C for it move on. Thanks again!
How to access Time Machine files from Linux
Here is a new version (One or two bugs corrected) :
Edited on Jan 06, '11 11:07:39AM by jeromemac75
How to access Time Machine files from Linux
I also noticed your old version went into infinite loops when it encountered symbolic links and also that it didn't copy files with special characters (like /, {, and } ). Does your new script correct this? Thanks
How to access Time Machine files from Linux
the new version addresses the link problem. The characters are not treated as /, { or } are not valid characters for file names within Linux. Thanks for your interest :)
How to access Time Machine files from Linux
Yes, but OS X supports characters like /, {, and } in filenames; it just converts them to something like "\/", "\{}," etc. Your script didn't copy a filename that had a "/" in OS X.
How to access Time Machine files from Linux
I just read the original post and thought, hey this would make a great candidate for a script, then thought someone else must have thought the same thing. True enough. Great script! Thanks! :-) |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.15 seconds |
|