Skip to content
Snippets Groups Projects
Verified Commit 7307ee9f authored by Davide Gardenal's avatar Davide Gardenal
Browse files

upgrade_oniro: implement backup_oniro


Implment backup_oniro, now the script can backup the project so
that in case something goes wrong in the upgrade we can restore
the initial state (this function is not yer implement).
Add TODOs.

Signed-off-by: Davide Gardenal's avatarDavide Gardenal <davide.gardenal@huawei.com>
parent 7247961a
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
# 7. In case of a successful upgrade print/dump some additional information about the upgrade (CVE diff, buildhistory, ...) # 7. In case of a successful upgrade print/dump some additional information about the upgrade (CVE diff, buildhistory, ...)
# #
# TODO think about a way to let the user know BEFORE the upgrade what changed so (s)he can choose. (maybe you can use git diff --compact-summary) # TODO think about a way to let the user know BEFORE the upgrade what changed so (s)he can choose. (maybe you can use git diff --compact-summary)
# TODO check if the script is executed in the top level directory of the project
# TODO check that if build_directory exists then it must be a directory
import argparse import argparse
import pathlib import pathlib
...@@ -94,7 +95,29 @@ def perform_pre_upgrade_checks(): ...@@ -94,7 +95,29 @@ def perform_pre_upgrade_checks():
return return
def backup_oniro(): def backup_oniro():
# TODO # This will back up:
# - All layers specified in the Oniro Manifest
# - .repo folder
# - If build_directory is not empty, backup its content excluding tmp* and tmp-newlib* directories
# TODO add function description
# TODO add more verbose log
from upgrade_oniro_utils import get_manifest_projects
from datetime import datetime
import tarfile
backup_folders = [layer["path"] for layer in get_manifest_projects()] # add all manifest layers
backup_folders.append(".repo")
if build_directory.exists():
for child in build_directory.iterdir():
if child.is_dir() and "tmp" not in child.name and child.name != "downloads":
backup_folders.append(f"{build_directory.name}/{child.name}")
archive_name = f"upgrade_oniro_backup-{datetime.timestamp(datetime.now())}.tar.gz"
with tarfile.open(archive_name, "w:gz") as tar_archive:
for folder in backup_folders:
tar_archive.add(folder)
print(f"{folder} has been backed up")
return return
def restore_oniro(): def restore_oniro():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment