-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmlx.sh
More file actions
71 lines (57 loc) · 3.14 KB
/
tmlx.sh
File metadata and controls
71 lines (57 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Copyright (c) 2020 Liam Whittle
# This software is covered by the MIT licence. Refer to LICENCE.txt.
# Use this program at your own risk. You must refer to README.md for how to use it.
# Path where the initial list of folders to copy is. Essentially, this path points to the
# latest backup. I'm not sure what to do if you want an older version of your backup... Honestly, you'll probably
# only want the stuff in "Users" - in that case find the corresponding PRIVATE_DIRECTORY_DATA folder and put that here.
# Use the instructions in the first link in README.md - this explains a lot of how the below code works as well :)
COPY_PATH=/home/$USER/TimeMachineMount/Backups.backupdb/Macintosh/Latest/Macintosh HD
# This is the main path where all the actual backup data resides.
DATA_PATH=/home/$USER/Desktop/TimeMachineMount/PRIVATE_DIRECTORY_DATA
# This is where we will be saving our extracted data. Edit to your liking.
PASTE_PATH=/home/$USER/Desktop/TimeMachineConverted
# The following is a recursive function. It traverses Apple's weird file system for backups and constructs an actual
# file system with all the files copied in. Please note that I learned bash for the first time while doing
# this... there's likely a way of doing it in one line with "find", but I couldn't work it out. If you do, please send
# a pull request!
# parameters: $1 = directory to search, $2 = directory to create within
create_dirs()
{
local SEARCH_DIR=$1
local WRITE_DIR=$2
# enter the search directory for search
cd "${SEARCH_DIR}"
for file in *
do
# Re enter directory (recursive calls will possibly have changed it)
cd "${SEARCH_DIR}"
# extract the file pointer using a regular expression
local PTR=$(ls -l "${file}">&1)
local NUM=$(echo "$PTR" | grep -oh "[0-9]*" | head -1)
# CONTAINER_DIR is the absolute path to a potential file container
local CONTAINER_DIR=${DATA_PATH}/dir_${NUM}
# if the pointer points to a directory, create and recurse
if [[ -d "${CONTAINER_DIR}" ]]; then
# make the directory in the skeleton path
mkdir "$WRITE_DIR/$file"
# recursively create required directories. echo below for debug
echo "create_dirs $CONTAINER_DIR $WRITE_DIR/$file"
create_dirs "$CONTAINER_DIR" "$WRITE_DIR/$file"
# if the object we have examined is actually a directory, copy the directory name over and recurse
elif [[ -d "${SEARCH_DIR}/${file}" ]]; then
# make the directory in the skeleton path
mkdir "$WRITE_DIR/$file"
# recursively create required directories from the CURRENT directory - NOT the container directory
echo "create_dirs $SEARCH_DIR_DIR/$file $WRITE_DIR/$file"
create_dirs "$SEARCH_DIR/$file" "$WRITE_DIR/$file"
# if it is simply a file, we can copy it over
elif [[ -f "${SEARCH_DIR}/${file}" ]]; then
cp "${SEARCH_DIR}/${file}" "${WRITE_DIR}" -v
fi
cd "${SEARCH_DIR}"
done
}
# recursively search through directories starting with DATA_PATH, the path to search for directory pointers,
# and PASTE_PATH, the path to past in a new directory structure.
create_dirs $COPY_PATH $PASTE_PATH