% SPDX-License-Identifier: GPL-3.0-or-later OR CC-BY-SA-4.0
\section{Back up/Restore}\label{sec:backup-restore} %%##$section-title>>
%%!!intro<<
App Manager has a modern, advanced and easy-to-use backup/restore system implemented from the scratch.
This is probably the only app that has the ability to restore not only the app or its data but also permissions and
rules that you've configured within App Manager.
You can also choose to back up an app multiple times (with custom names) or for all users.

\begin{amseealso}
    \item \hyperref[subsec:1-click-back-up]{1-Click Ops: Back up}
    \item \hyperref[subsec:1-click-restore]{1-Click Ops: Restore}
\end{amseealso}
%%!!>>

\subsection{Location}\label{subsec:backup-location} %%##$location-title>>
%%!!location<<
Back up/restore is a part of \hyperref[subsec:batch-operations]{batch operations}.
It is also located inside the \hyperref[subsubsec:app-info-options-menu]{options menu} in the
\hyperref[subsec:app-info-tab]{App Info tab}.
Clicking on \textbf{Backup/Restore} opens the \textbf{Backup Options}.
Backups are located at \texttt{/storage/emulated/0/AppManager} by default.
You can configure custom backup location in the \hyperref[subsubsec:backup-volume]{settings page} in which case the backups
will be located at the \texttt{AppManager} folder in the selected volume.

\begin{tip}{Note}
    If one or more selected apps do not have any backup, the \textbf{Restore} and \textbf{Delete Backup} options will
    not be displayed.
\end{tip}
%%!!>>

\subsection{Backup Options}\label{subsec:backup-restore-backup-options} %%##$options-title>>
%%!!options<<
Backup options (internally known as backup flags) let you customise the backups on the fly.
However, the customisations will not be remembered for the future backups.
If you want to customise this dialog, use \hyperref[subsubsec:settings-backup-options]{Backup Options} in the \hyperref[sec:settings-page]{Settings page}.

A complete description of the backup options is given below:
\begin{itemize}
    \item \textbf{APK files.} Whether to back up the APK files.
    This includes the \textit{base APK} file along with the \texttt{split APK} files if they exist.

    \item \textbf{Internal data.} Whether to back up the internal data directories.
    These directories are located at \texttt{/data/user/<user\_id>} and (for Android N or later) \texttt{/data/user\_de/<user\_id>}.

    \item \textbf{External data.} Whether to back up data directories located in the internal memory as well as SD Card (if exists).
    External data directories often contain non-essential app data or media files (instead of using the dedicated media folder) and may increase the backup size.
    However, it might be essential for some apps.
    Although it isn't checked by default (as it might dramatically increase the size of the backups), you may have to check it in order to ensure a smooth restore of your backups.
    \begin{warning}{Caution}
        Internal data folders should always be backed up if you are going to back up the external data folders.
        However, it could be useful to back up only the external folders if the app in question downloads a lot of assets from the Internet.
    \end{warning}

    \item \textbf{OBB and media.} Whether to back up or restore the OBB and the media directories located in the
    external storage or the SD Card.
    This is useful for games and the graphical software which actually use these folders.

    \item \textbf{Cache.} Android apps have multiple cache directories located at every data directories (both internal and external).
    There are two types of cache: \textbf{cache} and \textbf{code cache}.
    Enabling this option excludes both cache directories from all the data directories.
    It is generally advised to exclude cache directories since most apps do not clear the cache regularly (for some
    reason, the only way an app can clear its cache is by deleting the entire cache directory) and usually handled by the OS itself.
    Apps such as Telegram may use a very large cache (depending on the storage space) which may dramatically increase the backup size.
    When it is disabled, AM also ignores the \textbf{no\_backup} directories.

    \item \textbf{Extras.} Backup/restore app permissions, net policy, battery optimization, SSAID, etc., enabled by default.
    Note that, blocking rules are applied \textit{after} applying the extras.
    So, if an item is present in both places, it will be overwritten (i.e., the one from the blocking rules will be used).

    \item \textbf{Rules.} This option lets you back up blocking rules configured within App Manager.
    This might come in handy if you have customised permissions or block some components using App Manager as they will
    also be backed up or restored when you enable this option.

    \item \textbf{Backup Multiple.} Whether this is a multiple backup.
    By default, backups are saved using their user ID\@.
    Enabling this option allows you to create additional backups.
    These backups use the current date-time as the default backup name, but you can also specify custom backup name
    using the input field displayed when you click on the \textbf{Backup} button.

    \item \textbf{Custom users.} Backup or restore for the selected users instead of only the current user.
    This option is only displayed if the system has more than one user.

    \item \textbf{Skip signature checks.} When taking a backup, checksum of every file (as well as the signing
    certificate(s) of the base APK file) is generated and stored in the \texttt{checksums.txt} file.
    When you restore the backup, the checksums are generated again and are matched with the checksums stored in the said file.
    Enabling this option will disable the signature checks.
    This option is applied only when you restore a backup.
    During backup, the checksums are generated regardless of this option.
    \begin{warning}{Caution}
        You should always disable this option to ensure that your backups are not modified by any third-party applications.
        However, this would only work if you enabled encryption.
    \end{warning}
\end{itemize}

\seealsoinline{\hyperref[subsubsec:settings-encryption]{Settings: Encryption}}
%%!!>>

\subsection{Backup}\label{subsec:backup-restore-backup} %%##$backup-title>>
%%!!backup<<
Backup respects all the backup options except \textbf{Skip signature checks}.
If base backups (i.e., backups that don't have the \textbf{Backup Multiple} option) already exist, you will get a warning as the backups will be overwritten.
If \textbf{Backup Multiple} is set, you have an option to input the backup name, or you can leave it blank to use the current date-time.
%%!!>>

\subsection{Restore}\label{subsec:backup-restore-restore} %%##$restore-title>>
%%!!restore<<
Restore respects all the backup options and will fail if \textbf{APK files} option is set, but the backup doesn't
contain such backups or in other cases, if the app isn't installed.
When restoring backups for multiple packages, you can only restore the base backups (see \hyperref[subsec:backup-restore-backup]{backup} section for an explanation).
However, when restoring backups for a single package, you have the option to select which backup to restore.
If \textbf{All users} option is set, AM will restore the selected backup for all users in the latter case but in the former case, it will restore base backups for the respective users.

\begin{tip}{Notice}
    Apps that use storage access framework (SAF), SSAID or Android KeyStore works properly only after an immediate restart.
\end{tip}
%%!!>>

\subsection{Delete Backup}\label{subsec:backup-restore-delete-backup} %%##$delete-title>>
%%!!delete<<
Delete backup only respects \textbf{All users} option and when it is selected, only the base backups for all users will be deleted with a prompt.
When deleting backups for a single package, another dialog will be displayed where you can select the backups to delete.
%%!!>>
