-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsave_archived
executable file
·83 lines (74 loc) · 2.2 KB
/
save_archived
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
DOMAIN="$1"
SUBDIR="archived_$DOMAIN"
type -P yawbdl &>/dev/null && ISINST=1 || ISINST=0
if [ $ISINST -eq 0 ]
then
echo "Install https://github.com/BGforgeNet/yawbdl"
exit 127
fi
if yawbdl -d $DOMAIN -o $SUBDIR --no-fail --retries 10 --delay 2; then
PERLDATETIME=$(perl -e 'my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - 30*86400); $year += 1900; $mon += 1; printf ("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday, $hour, $min, $sec)')
mv "$SUBDIR/snapshots.json" "$SUBDIR/snapshots_downloaded_$PERLDATETIME.json"
fi
exit
if [[ "$SAVESITE_MAXSNAPSHOTPAGES" == "" ]]
then
# increase it if need to backup huge sites, or better execute 'export SAVESITE_MAXSNAPSHOTPAGES=...' before running the script
MAXSP=100000
else
MAXSP="$SAVESITE_MAXSNAPSHOTPAGES"
fi
type -P wayback_machine_downloader &>/dev/null && ISINST=1 || ISINST=0
if [ $ISINST -eq 0 ]
then
echo "Install Ruby, then execute 'sudo gem install wayback_machine_downloader'"
echo "See also https://linuxnightly.com/how-to-download-a-website-from-the-wayback-machine"
echo ""
exit 127
fi
SUBDIR="archived_$DOMAIN"
if [ -e "$SUBDIR" ]; then
echo "$SUBDIR already exists (completely downloaded, but when?)"
elif [ -e "$SUBDIR.zip" ]; then
echo "$SUBDIR already exists (completely downloaded and zipped)"
exit
#elif [ -e "~$SUBDIR" ]; then
# echo "~$SUBDIR already exist (incompletely downloaded), you should remove it"
# exit 1
else
mkdir -p ~$SUBDIR
wayback_machine_downloader -s -p $MAXSP -c 1 -d ./~$SUBDIR http://$DOMAIN #| tee -a ./~$SUBDIR/wayback_machine_downloader.log
if [ $? -eq 0 ]
then
if [ -d "~$SUBDIR" ]; then
du -h ./~$SUBDIR
mv "~$SUBDIR" "$SUBDIR"
echo "$SUBDIR downloaded successfully (perhaps)"
else
exit
fi
else
echo "~$SUBDIR not downloaded"
exit 1
fi
fi
ZIPFILE="$SUBDIR.zip"
if [ -d "$SUBDIR" ]; then
if [ ! -e "$ZIPFILE" ]; then
zip -9 -T -r $ZIPFILE $SUBDIR
if [ $? -eq 0 ]; then
if [ ! -e "~$SUBDIR" ]; then
echo -n "Deleting ~$SUBDIR..."
mv "$SUBDIR" "~$SUBDIR"
rm -r "~$SUBDIR"
if [ $? -eq 0 ]; then
echo " Done"
else
echo ""
exit 1
fi
fi
fi
fi
fi