Skip to content
Snippets Groups Projects
Unverified Commit c2a3e5e8 authored by Andreas Olsson's avatar Andreas Olsson
Browse files

Initial commit

parents
Branches
Tags
No related merge requests found
*~
\#*#
LICENSE 0 → 100644
The MIT License (MIT)
Copyright (c) 2017 Andreas Olsson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# urandom-restore
If a file has been backed up to **/dev/null** there is a chance that
you might be able to restore it from **/dev/urandom**. That is what
_urandom-restore_ is for.
## Usage
_urandom-restore_ is called with the name of the file you want to
restore as its one argument.
$ ./urandom-restore taxes2016.ods
/tmp/tmpiy7xg93r/taxes2016.ods
To test backing up and restoring a file there is the included shell
script _test-backup-and-restore_.
$ ./test-backup-and-restore ~/Documents/taxes2017.ods
The original /home/andreas/Documents/taxes2017.ods does not match the restored /tmp/tmppxr16hsu/taxes2017.ods
## Limitations
The free version of _urandom-restore_ only supports restoring files
which are 50 MiB or smaller.
#!/bin/bash
set -eu
orgfile="$1"
cat "$orgfile" > /dev/null
shortname=$(basename "$orgfile")
restored=$(./urandom-restore "$shortname")
if diff -q "$orgfile" "$restored" > /dev/null; then
echo "The original $orgfile matches the restored $restored"; exit 0
else
echo "The original $orgfile does not match the restored $restored"; exit 1
fi
#!/usr/bin/python3
import os
import sys
from random import SystemRandom
from tempfile import mkdtemp
MAX_RESTORE_SIZE = 1024 * 1024 * 50
def usage():
print('Usage: {} file-to-restore'.format(sys.argv[0]))
sys.exit(1)
def urestore(path):
size = SystemRandom().randint(1, MAX_RESTORE_SIZE)
data = os.urandom(size)
with open(path, 'wb') as ftr:
ftr.write(data)
print(path)
def main():
if len(sys.argv) != 2:
usage()
filepath = sys.argv[1]
shortname = os.path.basename(filepath)
outdir = mkdtemp()
newpath = os.path.join(outdir, shortname)
urestore(newpath)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment