Skip to content

Commit

Permalink
add option to skip app cache when backing up
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed May 11, 2020
1 parent 6e1d2b1 commit 384bd2c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/main/java/dk/jens/backup/ShellCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ public int doBackup(Context context, File backupSubDir, String label, String pac
// -L because fat (which will often be used to store the backup files)
// doesn't support symlinks
String followSymlinks = prefs.getBoolean("followSymlinks", true) ? "L" : "";
String skipCache = prefs.getBoolean("skipCache", false) ? " --exclude cache" : "";
switch(backupMode)
{
case AppInfo.MODE_APK:
commands.add("cp " + packageApk + " " + backupSubDirPath);
break;
case AppInfo.MODE_DATA:
commands.add("cp -R" + followSymlinks + " " + packageData + " " + backupSubDirPath);
commands.add("rsync -r" + followSymlinks + skipCache + " " + packageData + " " + backupSubDirPath);
break;
default: // defaults to MODE_BOTH
commands.add("cp -R" + followSymlinks + " " + packageData + " " + backupSubDirPath);
commands.add("rsync -r" + followSymlinks + skipCache + " " + packageData + " " + backupSubDirPath);
commands.add("cp " + packageApk + " " + backupSubDirPath);
break;
}
Expand Down Expand Up @@ -133,7 +134,7 @@ public int doBackup(Context context, File backupSubDir, String label, String pac
TextUtils.join(", ", commands)), e);
writeErrorLog(label, e.toString());
}, this);
if(errors.size() == 1 ) {
if(errors.size() == 2 ) { // 2, because rsync adds another line when there is an error
String line = errors.get(0);
// ignore error if it is about /lib while followSymlinks
// is false or if it is about /lock in the data of firefox
Expand Down
4 changes: 3 additions & 1 deletion src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<string name="prefs_rememberFiltering">remember sort and filter</string>
<string name="prefs_summaryRememberFiltering">saves the chosen sorting and filtering method. only those marked by a checkbox in the menu is considered.</string>
<string name="prefs_followSymlinks">follow symbolic links</string>
<string name="prefs_summaryFollowSymlinks">always follow symbolic links when copying (cp -L)</string>
<string name="prefs_summaryFollowSymlinks">always follow symbolic links when copying (rsync -L)</string>
<string name="prefs_enableSpecialBackups">enable special backups</string>
<string name="prefs_backupExternalFiles">handle external data</string>
<string name="prefs_summaryBackupExternalFiles">backs up and restores data that is placed on the external storage (e.g. /sdcard/Android/data/)</string>
Expand Down Expand Up @@ -163,4 +163,6 @@
<string name="error_updating_schedule_mode">Error updating %1$s of schedule %2$d</string>
<string name="permission_not_granted">Permission to access external storage is required</string>
<string name="restart_dialog">Application seems to need to be restarted</string>
<string name="prefs_skipCache">skip application cache</string>
<string name="prefs_summaryskipCache">skip backing up the cache for apps</string>
</resources>
6 changes: 6 additions & 0 deletions src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
android:summary="@string/prefs_summaryFollowSymlinks"
android:defaultValue="true"
/>
<CheckBoxPreference
android:key="skipCache"
android:title="@string/prefs_skipCache"
android:summary="@string/prefs_summaryskipCache"
android:defaultValue="false"
/>
<CheckBoxPreference
android:key="backupExternalFiles"
android:title="@string/prefs_backupExternalFiles"
Expand Down

0 comments on commit 384bd2c

Please sign in to comment.