This topic describes the available backup modes and how to restore a backup.
Backup modes
-
Full and incremental: By default, Codeup uses a full and incremental backup mode to speed up backups and reduce storage usage.
-
Archive and cleanup: Backup data is automatically archived every seven days. You can delete historical archives to free up storage space and reduce Object Storage Service (OSS) costs.
Full and incremental backups
Full backup
A full backup is a complete copy of your repository, including all refs and objects. This process can be time-consuming. After a successful backup, you can download the full backup file from OSS and easily restore it as a Git repository. For more details on the restoration process, see the sections below.
By default, Codeup performs a full backup for a repository's first backup, as no previous backups exist in OSS. For example, if a repository with the organization repository path alibaba/codeup.git is successfully backed up, the backup files are stored in OSS with the following path structure:
Storage path: All backups for an organization, excluding archives, are stored in a directory named repositories within an OSS bucket. The storage path format for a repository's backup files is /repositories/<organization repository path>/<repository UUID>, where:
-
The first-level directory,
/repositories, is the root path for all organization repository backups. -
The second-level directory,
<organization repository path>, is the path of the organization repository, such asalibaba/codeupin this example. -
The third-level directory,
<repository UUID>, is the unique identifier for the repository.
Backup-related files:
-
File naming format: A single repository backup generates and uploads multiple files. These files share a common prefix but have different extensions. For example, a backup might generate four files with the prefix
alibaba_codeup-full-20210223094414and varying file extensions. -
.bundlefile: This is the core backup file. You can use it to restore the backup as a Git repository. -
.listfile: This file contains a summary of the repository's ref information at the time of the backup. By comparing different .list files, you can easily track changes to refs (updates, additions, or deletions) between backups. -
.checksumfile: This file contains the checksum value of the repository data at the time of the backup. You can ignore this file. -
.lsremotefile: This file records the ls-remote command output for the bundle file after the backup is created. You can ignore this file.
Incremental backup
Incremental backups are slightly more complex than full backups but typically use less backup space and complete faster. If Codeup finds a previous backup in the /repositories/<organization repository path>/<repository UUID> directory, it performs an incremental backup instead of a full one.
Scenario: Incremental backup with repository updates
Assume a full backup file already exists for the repository. Before the next backup is triggered, new code is pushed to a branch in the repository. When a new backup is initiated, Codeup performs an incremental backup because the repository has been updated.
-
Storage path: The storage path for an incremental backup is the same as for a full backup. The path format remains
/repositories/<organization repository path>/<repository UUID>. The new backup files are:# Four incremental backup files are generated. The sequence number is 1, as reflected in the filenames: alibaba_codeup-inc-1-20210224074738.bundle alibaba_codeup-inc-1-20210224074738.checksum alibaba_codeup-inc-1-20210224074738.list alibaba_codeup-inc-1-20210224074738.lsremote
-
File naming format: Incremental backup files are similar to full backup files and have the same file types. The main difference is the naming convention. Full backup files are identified by
full, while incremental backup files are identified byinc-<order>, where<order>is the sequence number of the increment.
Scenario: Incremental backup with no repository updates
If an incremental backup is triggered for a repository with no updates, such as no new commits or only ref deletion operations (for example, deleting a branch), no .bundle or .lsremote file is generated.
# Three incremental backup files are generated. The sequence number is 2 because this is the second incremental backup:
alibaba_codeup-inc-2-20210224082031.bundle.log
alibaba_codeup-inc-2-20210224082031.checksum
alibaba_codeup-inc-2-20210224082031.list
-
*.bundle.logfile: Since the repository has no updates, this incremental backup does not generate a.bundleor.lsremotefile. Instead, it creates a.bundle.logfile, which explains why a.bundlefile was not created:# alibaba_codeup-inc-2-20210224082031.bundle.log file Content: fatal: Refusing to create empty bundle.
Although no bundle file is created, the backup is still considered successful. This is because ref deletions may have occurred, which can be tracked by comparing the new .list file with the one from the previous backup.
Archive historical backups
As explained earlier, repository backup files are stored in the /repositories/<organization repository path>/<repository UUID> directory. As the number of backups grows, managing and finding specific backup files can become difficult. To solve this, Codeup provides a feature to archive historical backups, which also helps save on storage costs.
Trigger condition: The archive process triggers automatically when the number of .bundle files in the /repositories/<organization repository path>/<repository UUID> directory is greater than or equal to seven. Codeup moves all existing backup files in the /repositories/<organization repository path>/<repository UUID> directory to an archive directory at /archive/<organization repository path>/<repository UUID>/rotate-<archive_date>. After the files are archived, Codeup automatically initiates a new full backup.
The archive directory contains all backup files from the previous backup cycle.
Restore from a backup
After a successful backup, you can view the backup files in your OSS bucket.
On the Repository Backup page, in the backup space area, click the Go to Backup Space link to navigate to the authorized OSS bucket (for example, a bucket named demo-misha in the China (Hangzhou) region) to view the backup files. In the Manual Backup area, you can confirm that the last execution result was Success.
Restore from full backup
-
Download the full backup file from OSS to your local machine:
➜ ls |grep bundle alibaba_codeup-full-20210224084658.bundle -
After downloading the bundle file, use it to restore the repository:
➜ git clone alibaba_codeup-full-20210224084658.bundle Cloning into 'alibaba_codeup-full-20210224084658'... Receiving objects: 100% (6/6), done. ➜ cd alibaba_codeup-full-20210224084658 ➜ ls -ltra total 8 drwx------@ 7 tenglong.tl staff 224 2 24 16:54 .. drwxr-xr-x 4 tenglong.tl staff 128 2 24 16:54 . -rw-r--r-- 1 tenglong.tl staff 6 2 24 16:54 test.file drwxr-xr-x 13 tenglong.tl staff 416 2 24 16:54 .git
Restore from incremental backup
Restoring from an incremental backup is similar to restoring from a full backup but slightly more complex. It involves a fetch operation instead of a clone. Assume you have backup files created at four different times (T0, T1, T2, and T3):
-
T0: The corresponding bundle file is
alibaba_codeup-full-20210224084658.bundle. -
T1: The corresponding bundle file is
alibaba_codeup-inc-1-20210224084659.bundle. -
T2: The repository has no incremental updates compared to T1, so no
.bundlefile is generated. Instead, a.bundle.logfile is created. -
T3: The corresponding bundle file is
alibaba_codeup-inc-3-20210224084700.bundle.
-
First, restore the repository from the T0 backup file. Download the full backup file
alibaba_codeup-full-20210224084658.bundleto your local machine and run thegit clonecommand:➜ git clone alibaba_codeup-full-20210224084658.bundle recovery.git -
recovery.gitis now a copy of the repository at time T0. -
To update the
recovery.gitrepository to its state at time T1, download the incremental backup file from T1,alibaba_codeup-inc-1-20210224084659.bundle, to your local machine and run the following commands:➜ cd recovery.git ➜ git remote add inc-1 ~/Downloads/alibaba_codeup-inc-1-20210224084659.bundle ➜ git fetch inc-1 Receiving objects: 100% (6/6), done. From /Users/tenglong.tl/Downloads/alibaba_codeup-inc-1-20210224084659.bundle * [new branch] topic_2 -> inc-1/topic_2 * [new branch] master -> inc-1/master * [new tag] v2.0 -> v2.0 -
The incremental changes from T1 have been successfully fetched into the
recovery.gitrepository. To switch to one of the updated branches, run the following command:➜ git checkout -b topic_2 inc-1/topic_2 Branch 'topic_2' set up to track remote branch 'topic_2' from 'inc-1'. Switched to a new branch 'topic_2' -
To apply the changes from T3 on top of the T0 repository, download the incremental backup file from T3,
alibaba_codeup-inc-3-20210224084700.bundle, and run the following commands:➜ git remote add inc-3 ~/Downloads/alibaba_codeup-inc-3-20210224084700.bundle ➜ git fetch inc-3 Receiving objects: 100% (3/3), done. From /Users/tenglong.tl/Downloads/alibaba_codeup-inc-3-20210224084700.bundle * [new branch] master -> inc-3/master -
Similarly, the incremental changes from T3 have now been fetched into the
recovery.gitrepository. Themasterbranch was updated. To check out themasterbranch as it was at time T3, run the following commands:➜ git checkout master ➜ git pull inc-3 master From /Users/tenglong.tl/Downloads/alibaba_codeup-inc-3-20210224084700.bundle * branch master -> FETCH_HEAD Updating 324711e..4bdbff9 Fast-forward lol.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 lol.txtThe
masterbranch is now restored to its state at T3.
-
If you only need to restore to the point in time of a full backup, download the corresponding full backup file and run
git clone <xxxx-full-xxxx.bundle>. -
To restore from an incremental backup, you must apply the backup chain chronologically, starting from a full backup. For example, to restore the repository to its state at time T3, you must first restore the full backup from T0, then apply the incremental backups from T1 and T3 in sequence. You must apply all available
.bundlefiles in the chain; attempting to skip one or apply them out of order will fail.