-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc.fish
executable file
·46 lines (40 loc) · 1.43 KB
/
proc.fish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env fish
# backup several courses at once iterating over a file of course ID numbers
# usage: ./proc.fish [N]
# where N is the number of backups to make
# defaults
# TODO IDFILE should be a parameter, too
set IDFILE data/ids.csv
set LINES 5
set LOGFILE data/(dt).log
# number of backups to make
if string match --regex --quiet '[0-9]+' $argv[1]
set LINES $argv[1]
end
set_color --bold
echo (date) "Backing up $LINES courses from list of IDs in $IDFILE"
set_color normal
for id in (head -n $LINES $IDFILE)
begin
echo (date) "Backing up course $id"
./backup.fish mk $id
# TODO if there's a random backup not created by this script it'll get
# downloaded over & over; may need to catch the complete backup filename
# from the last command & download just that
and ./backup.fish dl --all | gsed -e '/tar: Removing leading/d'
# no way to disable gsutil progress indicator which fills the logs with garbage
and ./backup.fish cp 2020FA data/backup_"$id"_* | tail -n1
and ./backup.fish rm $id
end &>>$LOGFILE
if test $status -ne 0
set_color red
echo (date) "ERROR: problem while backing up course $id" >>$LOGFILE
set_color normal
else
echo (date) "Successfully backed up course $id" >>$LOGFILE
gsed -i -e "/^$id\$/d" $IDFILE
end
end
set_color --bold
echo (date) "Finished backing up $LINES courses."
set_color normal