bakfile / bak Goto Github PK
View Code? Open in Web Editor NEWThe bakfile manager
License: MIT License
The bakfile manager
License: MIT License
When I run bak down file -k 1
, the following message is printed to stdout:
Confirm: Restore /tmp/tuterm/home1/todo.txt from bakfile #1 and bakfiles ? [y/N]: y
NOT KEEP_BAKFILE: []
I'm assuming this is a python debug message or something. It would be nicer if the message said <N> bakfiles discarded
or similar.
Relying on hooks probably isn't good enough, either, because who wants to do it twice?
Fortunately, bak can run a version check against config, and store a lightweight file indicating steps per version. Nothing fancy required. Add a breaking doohickey, add a version step.
Might as well. Typing python3 bak
is getting old.
So whenever I do bak up
, it works, but I also get An error occurred.
after the bakfile is made.
And then when I try to do bak down
to restore the test file, I get:
Overwrite /home/user/src/bak/TEST? [y/N]: y
Confirm: Restore /home/user/src/bak/TEST to /home/user/src/bak/TEST and erase bakfiles? [y/N]: y
Traceback (most recent call last):
File "/usr/local/bin/bak", line 33, in <module>
sys.exit(load_entry_point('bak==0.0.2a1', 'console_scripts', 'bak')())
File "/usr/lib/python3/dist-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3/dist-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.9/dist-packages/bak-0.0.2a1-py3.9.egg/bak/__main__.py", line 102, in bak_down
File "/usr/local/lib/python3.9/dist-packages/bak-0.0.2a1-py3.9.egg/bak/commands/__init__.py", line 274, in bak_down_cmd
File "/usr/lib/python3.9/pathlib.py", line 1377, in rename
self._accessor.rename(self, target)
OSError: [Errno 18] Invalid cross-device link: '/root/.local/share/bak/bakfiles/home-user-src-bak-TEST.1613262086-135462.bak' -> '/home/user/src/bak/TEST'
I've been messing around with bak reinstalling and such, but this happens after I've fully uninstalled any past installation and deleted, I believe, all the leftover files. It's possible this might be a permissions problem, but I recently recursively chowned and chmodded my homedir to 751 so that's probably not it. Also, it seemed to work pretty flawlessly on the very first install, no errors with bak up
, bak down
or anything else.
I installed this in a virtualenv on my desktop and couldn't get the bak up <file>
command to work.
I installed with this process:
git clone git clone https://github.com/bakfile/bak.git
'virtualenv bak/
source bak/bin/activate
python3 bak/setup.py install
When I just typed bak
I would get a help menu so I assumed it was installed properly.
The problem occurs when I tried to use bak up test.cfg
for the first time I got an error that looks like this:
> bak up test.cfg
Traceback (most recent call last):
File "/home/user/bak/bin/bak", line 33, in <module>
sys.exit(load_entry_point('bak==0.0.1a1', 'console_scripts', 'bak')())
File "/home/user/bak/lib/python3.6/site-packages/click-7.1.2-py3.6.egg/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/user/bak/lib/python3.6/site-packages/click-7.1.2-py3.6.egg/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/user/bak/lib/python3.6/site-packages/click-7.1.2-py3.6.egg/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/user/bak/lib/python3.6/site-packages/click-7.1.2-py3.6.egg/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/user/bak/lib/python3.6/site-packages/click-7.1.2-py3.6.egg/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/user/bak/lib/python3.6/site-packages/bak-0.0.1a1-py3.6.egg/bak/__main__.py", line 45, in bak_up
File "/home/user/bak/lib/python3.6/site-packages/bak-0.0.1a1-py3.6.egg/bak/commands/__init__.py", line 227, in bak_up_cmd
File "/home/user/bak/lib/python3.6/site-packages/bak-0.0.1a1-py3.6.egg/bak/commands/__init__.py", line 95, in _do_select_bakfile
I checked out the offending file and line number and it looks like this:
90 def _do_select_bakfile(bakfiles: List[bakfile.BakFile],
91 select_prompt=default_select_prompt,
92 err=True):
93 console = Console(file=stderr if err else stdout)
94 console.print(
95 f"Found {len(bakfiles)} bakfiles for file: {bakfiles[0].orig_abspath}")
96 console.print("Please select from the following: ")
97 console.print("Range %d", len(bakfiles))
On line 95 there is that bakfiles[0]
reference, and since the error was a IndexError I figured it was the culprit. I commented those couple of print lines out and reinstalled it. After that I could run the bak up test.cfg
command but I didn't really understand the menu that pops up after:
Enter a number to overwrite a .bakfile, or:
(V)iew (L)ist (C)ancel [C]:
This was sort of confusing and I didn't know what to do and after trying all the options I can say that the file seems to not have backed up anything.
I hope this can be a useful issue. I didn't dive into understanding the code much but am willing to help solve it with some direction.
Also, I think there is need for install guide in the README. I found a way to do it but I'm not sure if that is the best way.
It's confusing when they jump around the list. I've just restored the wrong .bakfile. An alternative solution might be showing the file in $EDITOR or $PAGER before the confirmation dialog.
Things are better now that bak respects the XDG directory spec, but it should still be configurable.
I just wanted to say, thank you for making this - I love it!
It's so cool having a proper manager for bakfiles, as early in development as it may be. So glad this exists.
(This is not an issue so it can be deleted to prevent clutter. I just wanted to show my appreciation.)
Doing bak anyfile
throws
Traceback (most recent call last):
File "/home/valence/.local/bin/bak", line 33, in <module>
sys.exit(load_entry_point('bak==0.2.1a1', 'console_scripts', 'bak')())
File "/home/valence/.local/bin/bak", line 25, in importlib_load_entry_point
return next(matches).load()
StopIteration
Implement bak down
, the command to delete your modified file and restore it from its .bakfile
bak off <filename>
is the command to run when you're satisfied with your changes, and want to remove the .bakfile associated with <filename>
It won't work everywhere, but if os.geteuid()
returns 0
, we're definitely root or root-like, and we should tell the user.
WARNING: You are running bak as root! This will create separate config and bakfiles for root, and is probably not what you're trying to do.
If bak needs superuser privileges to copy or overwrite a file, it will invoke `sudo cp` by itself.
Are you sure you want to continue as root? (y,N)
Hi, I have used this program for a few days and I really like it. One thing did annoy me though. When the file I am backing up is nested deep in a directory tree under my working directory, and I want to restore it using bak down
, it is not very convenient to have to specify the file's relative path.
It would be very useful if we could specify the file to restore with bak down
using the number, as we can do with bak del
. Maybe there is a use case to enable that for other commands as well.
In order to disambiguate a bakfile number from a file that has a number as its name, maybe we can prepend the number with something. For example bak down @1
will restore the bak file numbered 1 and bak down 1
will restore the file ./1
. You may have better suggestions than this.
The cfg module is handy for devs, but a little tough on users. bak
should
include a set of commands like bak config set
and bak config get
.
When bak
finds multiple .bakfiles matching the filename provided:
bak up
asks for clarification, or defaults to most recent
bak down
asks which .bakfile to restore
bak off
clarifies the number of .bakfiles that will be deleted (confirmation prompt needs to become more granular)
Goes with #13
If I've just done bak diff foo.cfg
, I've just seen the selection menu for foo.cfg
. I don't need it to come up again when I run bak down foo.cfg
. I should be able to do bak down 2 foo.cfg
(slightly less intuitive) or bak down foo.cfg 2
(riskier) to skip the dialog and restore that .bakfile. Since they're always sorted by "last modified"/"last restored" (#37) they're guaranteed to display the same number on the next invocation (assuming you haven't done a bak up
in the meantime.)
Line 251 in c042b23
bak off filename
currently asks you to confirm the operation before checking to see if it even has a filename.###.bak
. It should wait until it knows it can complete the operation before asking you to confirm.
Dumb Click magic. Shouldn't take 20 minutes, just boring.
The code's not too well documented, but, between my downtime and random passersby, this seems like it oughta be doable in October. test-requires
currently has pytest
and pytest-cov
.
Also, GitHub Actions to run those unit tests would be a bonus. Coverage is the bigger deal.
Needs a try/except or a sanity check or something
When bak
finds multiple .bakfiles matching the filename provided:
bak up
asks for clarification, or defaults to most recent
bak down
asks which .bakfile to restore
bak off
clarifies the number of .bakfiles that will be deleted (confirmation prompt needs to become more granular)
Goes with #13
bak list
should display a list of all .bakfiles, with metadata and so forth. bak list <filename>
should display only those .bakfiles corresponding to (obviously.)
bak print <filename>
should call $PAGER <bakfile>
.
bak print --with <program> <filename>
should call <program> <bakfile>
bak print --pipe <filename>
should output <bakfile>
to stdout, so it can be piped
aliases: -w
, -p
I am used to CLI commands having the -h
option for help. I know I can use just bak
to see the help message, but often I type the -h
by habit. It's very annoying.
Issue to keep track of suggestions, but if somebody reading this wants to chime in, here's the deal: bak get-bak
was chosen because, as far as I can tell, there is no good name for what that does. It's a clunky Beatles reference, for lack of a better idea.
The command outputs the abspath of a .bakfile, which is kind of a niche function. It's for situations where bak open --in exec
is too naive to do what you want. To the old version. The backup version. Of a file on which you are currently working.
$bak get-bak ~/bar/baz/foo.txt
/home/you/.local/share/bak/bakfiles/home-you-bar-baz-foo.txt.time-stamp.bak
Throw it in your favorite eval() and enjoy... what a dumb, but occasionally necessary command.
Still, it's the only one with a long name, and the only one with a dash in it, so it might as well get something better.
Suggestions on reddit so far include:
bak get
or bak path
(/u/posherspantspants)
bak where
, bak find
, or bak locate
(/u/nehtg0ste)
I'm also considering bak loc
because it's short. All of these, to me, sound like they imply something more useful than what get-bak
does.
This is easily fixable with exception handling; would be done already, but first retire #52
Line 7 in 2fe98b3
bak
is only designed to work on files. It might someday get an option to work on directories, or perhaps a recursive "bak 'em all" method, because recursive dir copies aren't unheard of. In the meantime, however, bak
should catch IsADirectoryError
, and output an error instead of crashing.
bak foo.cfg bak foo.cfg bak foo.cfg
Alternatively, allow bak off --except
or bak off --keep bak1 [bak2]...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.