Skip to content

Commit 572623e

Browse files
authored
Merge pull request #20 from dirkpetersen/dirk
archive --newer option
2 parents 99919ac + a398187 commit 572623e

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ froster archive \
500500
Total space to archive: 54,142 GiB
501501
```
502502

503+
Note: you can also use `--newer xxx --larger yyy to identify files that have only been added recently`
504+
503505
### Special use cases
504506

505507
#### Recursive operations

Diff for: froster.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,11 @@ def subcmd_archive(args,cfg,arch,aws):
452452
SELECTEDFILE = os.path.join(hsfolder, retline[0])
453453
else:
454454
SELECTEDFILE = os.path.join(hsfolder, csv_files[0])
455-
if args.larger > 0 and args.older > 0:
455+
if args.larger > 0 and (args.older > 0 or args.newer > 0):
456456
# implement archiving batchmode
457457
arch.archive_batch()
458458
return
459-
elif args.larger > 0 or args.older > 0:
459+
elif args.larger > 0 or args.older > 0 or args.newer > 0:
460460
print('You need to combine both "--older <days> and --larger <GiB> options')
461461
return
462462

@@ -1211,7 +1211,14 @@ def archive_batch(self):
12111211
conn.execute(f"CREATE TABLE hs AS SELECT * FROM read_csv_auto('{SELECTEDFILE}')")
12121212

12131213
# Now, you can run SQL queries on this virtual table
1214-
rows = conn.execute(f"SELECT * FROM hs WHERE {agefld} > {args.older} and GiB > {args.larger} ").fetchall()
1214+
if args.older > 0:
1215+
rows = conn.execute(f"SELECT * FROM hs WHERE {agefld} > {args.older} and GiB > {args.larger} ").fetchall()
1216+
elif args.newer > 0:
1217+
rows = conn.execute(f"SELECT * FROM hs WHERE {agefld} < {args.newer} and GiB > {args.larger} ").fetchall()
1218+
else:
1219+
print('You must either specify --older or --newer')
1220+
conn.close()
1221+
return False
12151222

12161223
totalspace = 0
12171224
cmdline = ""
@@ -5443,6 +5450,15 @@ def parse_arguments():
54435450
options are set froster will print a command that
54445451
allows you to archive all matching folders at once.
54455452
'''))
5453+
parser_archive.add_argument('--newer', '-w', dest='newer', type=int, action='store', default=0,
5454+
help=textwrap.dedent(f'''
5455+
Archive folders that have been accessed within the last
5456+
<days>. (optionally set --mtime to select folders that
5457+
have not been modified more than <days>). This option
5458+
works in conjunction with --larger <GiB>. If both
5459+
options are set froster will print a command that
5460+
allows you to archive all matching folders at once.
5461+
'''))
54465462
parser_archive.add_argument( '--mtime', '-m', dest='agemtime', action='store_true', default=False,
54475463
help="Use modified file time (mtime) instead of accessed time (atime)")
54485464
parser_archive.add_argument( '--recursive', '-r', dest='recursive', action='store_true', default=False,

Diff for: tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ generate_test_data() {
7575

7676
# Execute the function and capture the returned folder path
7777
created_folder=$(generate_test_data)
78-
78+
echo "Test data folder: $created_folder"
7979

8080
script_dir=~/.local/bin
8181

0 commit comments

Comments
 (0)