Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two new functions: "Backup" and "Recover" #57

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

amirali-dashti
Copy link

Hello Rhino Linux Team,

I’d like to submit this pull request to introduce two new utilities: rpk backup and rpk recover. Below are the details of their functionality and rationale.

Intent

The rpk backup utility records the names of all installed packages (from different sources) to create a backup for a specific device. The rpk recover command reads this backup file and installs any missing packages on another system.

Context

This update enables users to log and save their installed package data, allowing them to replicate the same environment on another device using the recover command. This is particularly useful for migration, disaster recovery, or consistent setup across multiple machines.

Logic of backup

  1. The user selects where to save the backup file (e.g., a default path with a timestamped filename or a custom path/name).
  2. The utility verifies the file’s safety before writing.
  3. Installed packages are collected and categorized by their package manager (e.g., dpkg, snap).
[username] sudo ./rhino-pkg backup
The backup file's location: '/rhino-pkg_backup_20250213_172315.txt'
Continue (y), or choose your own .txt file (S)? (y/S) y
Creating the file: /rhino-pkg_backup_20250213_172315.txt
Using the file: /rhino-pkg_backup_20250213_172315.txt
Backup location: /rhino-pkg_backup_20250213_172315.txt
Starting backup process...
Collecting installed package names...
Backup completed successfully!
Backup saved to: /rhino-pkg_backup_20250213_172315.txt
SHA256: 9e382d149b9f0e06e120399f86728bf14508670fe4f3f21399f0e614677a23e0

The logic of recover

  1. Validates the backup file’s readability and integrity.
  2. Installs missing packages using their respective package managers.
  3. Displays a summary of failed installations.
  4. Prompts the user to run a system update and cleanup post-recovery.
$ sudo ./rhino-pkg recover /rhino-pkg_backup_20250213_172315.txt
Using the file: /rhino-pkg_backup_20250213_172315.txt              
Do you want to recover files by downloading packages again (WARNING: YOU CANNOT CANCEL THE OPERATION! Internet bandwidth usage warning!)? (y/N) y
Starting recovery...
Do you want to update first? (y/N) N
Skipping update.
Recovering dpkg/apt packages...
accountsservice is already the newest version (23.13.9-7ubuntu1).
Summary:
  Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 0
'accountsservice' is installed successfully.
acl is already the newest version (2.3.2-2).
Summary:
  Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 0
'acl' is installed successfully.
adduser is already the newest version (3.137ubuntu2).
Summary:
  Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 0
'adduser' is installed successfully.
Package adw-gtk-theme is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Error: Package 'adw-gtk-theme' has no installation candidate
Failed to install 'adw-gtk-theme'.
Package adw-gtk3 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Error: Package 'adw-gtk3' has no installation candidate
Failed to install 'adw-gtk3'.
.
.
.

Errors:

Failed to install the following dpkg/apt packages:
- adw-gtk-theme
- adw-gtk3
- appmenu-registrar
- celeste
- discord
.
.
.
Failed to install the following Snap packages:
- libsnapd-glib-2-1
- libsnappy1v5

Next Steps

This feature is in beta, and I welcome feedback on:

  • Naming conventions (e.g., backup/recover vs. save/restore)
  • Code structure improvements
  • Edge cases or security considerations

Let me know if any adjustments are needed before merging. I’m happy to iterate further!

Best regards,

@devtracer

@Elsie19
Copy link
Member

Elsie19 commented Feb 13, 2025 via email

@oklopfer
Copy link
Member

We should absolutely add this feature to the rewrite, though. We intended for a very similar concept with https://github.com/rhino-linux/horns, which never came to full fruition. Thank you immensely for this!

@ajstrongdev
Copy link
Member

This is absolutely incredible work. I would personally want to see this merged into the current (bash) version of rhino-pkg, and then we port it to the rewrite (whatever language that may be)

My concern is that there does not seem to be any handling for Pacstall packages, only apt/snap and flatpak. This would absolutely need to be rectified if this is to be merged into rhino-pkg.

@ajstrongdev
Copy link
Member

Additionally there seems to be no handling for Nala.

@Elsie19
Copy link
Member

Elsie19 commented Feb 14, 2025

We should absolutely add this feature to the rewrite, though. We intended for a very similar concept with rhino-linux/horns, which never came to full fruition. Thank you immensely for this!

Yes absolutely this should be added to the rewrite. Sorry if I didn't mention that in my first message, but that was my intention.

@amirali-dashti
Copy link
Author

Thanks for the great work! Unfortunately we're in the middle of a rewrite to another language, most likely Nushell, and you can find the progress at #52.

Thank you for your response, @Elsie19, and I’m glad you liked the project! Regarding the rewrite to Nushell (#52), I’d love to contribute to this effort as well.

My idea is to implement the backup and recover functions as a separate Bash script. This approach would:

  1. Allow users to retain these utilities even during the transition to Nushell.
  2. Keep the code modular, as these functions are distinct yet related to the core functionality.

I’ll share another idea soon. Looking forward to your thoughts!

@Elsie19
Copy link
Member

Elsie19 commented Feb 14, 2025

Are you familiar with Nushell?

@amirali-dashti
Copy link
Author

@oklopfer I’m thrilled to hear you liked the idea! My next suggestion aligns perfectly with this: I’d love to contribute to completing the Horns project. Once finalized, the future rpk package could integrate Horns (or a subset of it) to handle these processes.

We can discuss details like:

  • Implementation logic
  • Programming language choices
  • How to best integrate Horns with rpk

Looking forward to collaborating on this!

@amirali-dashti
Copy link
Author

Are you familiar with Nushell?

I’m not currently familiar with Nushell, but after looking it up, I find it quite interesting and am eager to learn it!

@amirali-dashti
Copy link
Author

@ajstrongdev

This is absolutely incredible work. I would personally want to see this merged into the current (bash) version of rhino-pkg, and then we port it to the rewrite (whatever language that may be)

I'm absolutely delighted to hear that you liked my project! It truly means a lot, and I’d be more than happy to contribute!

My concern is that there does not seem to be any handling for Pacstall packages, only apt/snap and flatpak. This would absolutely need to be rectified if this is to be merged into rhino-pkg.

Yes, you're completely right and I agree! I’ve included handling for Pacstall packages. Here’s how it works:

  1. Lines 123–124: Collects installed Pacstall packages and saves them to the backup file.
  2. Line 197: Tracks Pacstall packages that fail to install.
  3. Lines 210–211: Detects the Pacstall flag to switch to Pacstall’s installation method.
  4. Lines 228–231: Recovers Pacstall packages using:
    pacstall -I <package>  
  5. Lines 265–270: Reports any Pacstall packages that failed to install.

Let me know if there’s anything else I can clarify or improve!

@amirali-dashti
Copy link
Author

Additionally there seems to be no handling for Nala.

When the recovery process is complete, the code asks the user if they want to run an update and a cleanup as well. If the user agrees, the cleanup process will also be executed. If it's necessary to enforce a cleanup, we can modify the logic accordingly.

@ajstrongdev
Copy link
Member

Is the recovery supposed to be prompted throughout? pacstall -I will prompt the user on multiple steps.

@Elsie19 Elsie19 added the enhancement New feature or request label Feb 14, 2025
@amirali-dashti
Copy link
Author

Is the recovery supposed to be prompted throughout? pacstall -I will prompt the user on multiple steps.

Could you clarify further? The recovery process is designed to reinstall the required packages. The code identifies packages under the Pacstall tag and passes them to Pacstall for installation. If there are specific prompts or steps during pacstall -I that need to be addressed, please let me know!

@Elsie19
Copy link
Member

Elsie19 commented Feb 14, 2025

I assume he's talking about the -P flag on pacstall which bypasses prompts.

@amirali-dashti
Copy link
Author

I assume he's talking about the -P flag on pacstall which bypasses prompts.

Thanks for the explanation. So as it seems, I have to change -I to -P, am I right?

@Elsie19
Copy link
Member

Elsie19 commented Feb 14, 2025

I assume he's talking about the -P flag on pacstall which bypasses prompts.

Thanks for the explanation. So as it seems, I have to change -I to -P, am I right?

You should use -PI.

@amirali-dashti
Copy link
Author

You should use -PI.

Ok, I'll edit the code. Thanks.

Replaced ```Pacstall -I``` to ```Pacstall -PI```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants