You are not logged in.

#1 2025-07-13 19:51:43

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

bak script1 script2 script

How would a simple (but not to simple) backup script look like? (something to avoid 'cp script script.bak' nonsense). After some long talk with my best friend Chad Gpt I came up with this:

- Make script relatively simple
- Don't bother with directories (will only work with files)
- Don't pollute current dir, backup to predefined folder instead
- Avoid duplicates via checksums
- Have timestamps to simulate basic version control
- Store with full paths
- Make shellcheck happy

So for example

bak shell.script

will copy that shell.script to predefined $HOME/bak and store sha265 into $HOME/bak/.bak_index

Not tested very much, hot script
https://raw.githubusercontent.com/bront … ts/bin/bak

In action

❯ echo "one" > script

❯ cat script
one

❯ bak script
✓ Backed up 'script' → '/home/b/bak/home/b/tmp/script.20250713-220753'

❯ bak script
✗ Skipping 'script' — identical content already backed up

❯ echo "two" >> script

❯ bak script
✓ Backed up 'script' → '/home/b/bak/home/b/tmp/script.20250713-220811'

❯ bak script
✗ Skipping 'script' — identical content already backed up

❯ tree -a ~/bak
/home/b/bak
├── .bak_index
└── home
    └── b
        └── tmp
            ├── script.20250713-220753
            └── script.20250713-220811

4 directories, 3 files

p.s. 'restore/unbak' is up to the user at this point.

Offline

Board footer

Powered by FluxBB