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

Save old subvolume as a new snapshot #5

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

lepz0r
Copy link

@lepz0r lepz0r commented Dec 18, 2022

Instead of moving old subvolume to /btrfsroot/<subvol_main><date> we move old subvolume to /btrfsroot/<subvol_snapshots>/<new_snapshot_number>/snapshot and generate it's info.xml

Copy link
Owner

@jrabinow jrabinow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. This is a great idea!

For consistency reasons: could you please format these changes with black and use snake_case instead of camelCase wherever possible?

One consideration I have when seeing these changes, I'm assuming that this script might have to run in situations where the system is completely hosed: the snapper subvolume is read-only, or btrfs is messed up somehow.
What if there was a try/catch around the snapshot creation code, and if any exception was thrown, it reverted back to the current behavior?

I'm afraid my system is currently not online, so I can't create a new release right away, but I'll get to it as soon as I can.

snapper-rollback.py Outdated Show resolved Hide resolved
if dry_run:
LOG.info("Creating directory at {}".format(mountpoint / config.get("root", "subvol_snapshots") / dest))
else:
os.mkdir(mountpoint / config.get("root", "subvol_snapshots") / dest )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's an ensure_dir function which will handle a few edge cases when creating directories

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed os.mkdir in createNextSubvolumeNumber to ensure_dir

@@ -48,6 +49,39 @@ def parse_args():
args = parser.parse_args()
return args

def generateXML(fileName,type,num,date,description,cleanup,dry_run=False) :
Copy link
Owner

@jrabinow jrabinow Dec 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of these parameters are either hardcoded or could be determined inside this function (like date param).

Let's also have a description or userdata which shows this was an active rootfs the user rolled back from

Comment on lines 203 to 204
subvol_main_newname = pathlib.Path(f"{subvol_main}")
date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 variables are / should be unused now

Comment on lines 162 to 167
if dry_run:
subvol_main_snapshot_number = str(int(os.listdir(path= "/.snapshots")[-1])+1)
else:
subvol_main_snapshot_number = str(int(os.listdir(path=
mountpoint / config.get("root", "subvol_snapshots")
)[-1])+1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be the same whether dry-run or not.
Also, beware files not being listed in alphanumerical order. This should be sorted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants