aboutsummaryrefslogtreecommitdiff
path: root/android-backup
blob: 70c50069a8a510f7c014b326c0dd3e23eca45053 (plain)
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
#!/bin/bash
#
# Android backup
#

# Parameters
basename="`basename $0`"
name="$1"
date="`date +%Y%m%d`"
base="/storage/emulated/0"
storage="/var/backups/remote/$name.`facter domain`/"
previous="`sudo ls -1 $storage | tac | head -n 1`"

# Check
if [ -z "$name" ]; then
  echo "$basename: missing phone name"
  exit 1
fi

# Work folder
cd ~/load || exit 1
mkdir -p $date && cd $date

# Check
if [ -d "$storage/$date" ]; then
  echo "backup for $date already exists"
  exit 1
fi

# If you have a previous backup you might want to use it with hardlinks
if [ -e "$storage/$previous/files" ]; then
  sudo cp -alf $storage/$previous/files files
fi

# Ensure we have a files folder
mkdir -p files

# Contacts. Export also to a .vcf directly from the contact app
adb-export.sh           -e    content://com.android.contacts/contacts
adb shell content query --uri content://com.android.contacts/contacts > contacts.rows

# Configurations
adb backup -all

# Files: full copy
#adb pull $base files/

# Remove multimedia cache from backup
#rm -rf files/Music

# Files: full basic copy
#adb shell ls -1 $base | grep -v ^Music | while read file; do
#  adb pull $base/$file files/
#done

# Files: incremental basic copy
for file in `adb shell ls -1 $base | grep -v '^Music'`; do
  adb-sync --delete --reverse $base/$file files/
done

# Move backup to storage
cd .. && sudo mv $date $storage/