KNOXDEV / scoop-backup

Backup your entire current scoop installation with one command
The Unlicense
60 stars 6 forks source link

Feature Request: Scheduled Task #5

Closed brian6932 closed 1 year ago

brian6932 commented 2 years ago

So on Chocolatey, there's a similar backup package called CPLB for its packages respectively, and one feature from that package I find really handy is that it creates a scheduled task to backup my Chocolatey packages weekly. Would it be possible to port such a feature?

KNOXDEV commented 2 years ago

Sure.

CPLB creates a scheduled task by default, but I think scheduling a reoccurring backup should be an additional manual command for this module.

I'm currently thinking something along the lines of:

scoop-backup -s

where the new -s flag not only runs the backup script, but schedules it to reoccur on a weekly basis. In additional, you'll be able to provide a number of hours between backups to override the default of 168 (1 week).

I'll probably push this over the weekend but feel free to bump this issue if I forget.

Thanks for the suggestion.

brian6932 commented 2 years ago

I'll probably push this over the weekend but feel free to bump this issue if I forget.

^

KNOXDEV commented 2 years ago

Whoops, checking back in. I made an attempt at this but as it turns out, scheduling tasks in Windows is a non-negligible feat.

Here's the snags I've encountered:

  1. the option parsing logic that current exists in this script doesn't currently support parameters, only boolean flags, so that would have to be updated.
  2. scheduling a task will require an elevation of privileges. That means that this program suddenly has to concern itself with the privileges of the caller, and this is a bit of code to add. Or I can simply require the "sudo" package as a dependency, but if most people will never use it, it feels a little unnecessarily heavy.
  3. the interfaces that Windows provides for scheduling tasks suck. Check the code that your referenced package uses, there's lots of different cases to check, and deleting the task is similarly complicated.
  4. this is the big one. Essentially, the easiest way to have this work would be if the script called scoop-backup itself every so often, but unfortunately, the script relies on a user context and an easily-discoverable home directory into the libraries that scoop provides. This is not necessarily the case for this script, especially if its run by the system user. So, we'd need to do some additional refactors to make this work as expected.

If anybody else has a workaround suggestion or PR they want to push addressing this, be my guest. But I've basically bumped up against the amount of time I'm willing to spend on this atm.

For a determined user, consider using the Windows Task Scheduler. I couldn't even get it to work in this context, and debugging this was highly unpleasant, but I would assume refactors would be necessary.

brian6932 commented 1 year ago

closing ancient issues