diff options
-rwxr-xr-x | scripts/clean-hashserver-database | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/scripts/clean-hashserver-database b/scripts/clean-hashserver-database new file mode 100755 index 0000000000..9fa162c981 --- /dev/null +++ b/scripts/clean-hashserver-database | |||
@@ -0,0 +1,77 @@ | |||
1 | #!/bin/bash | ||
2 | set -euo pipefail | ||
3 | |||
4 | SSTATE_DIR="" | ||
5 | BB_HASHCLIENT="" | ||
6 | BB_HASHSERVER="" | ||
7 | |||
8 | ALIVE_DB_MARK="alive" | ||
9 | CLEAN_DB="false" | ||
10 | THRESHOLD_AGE="3600" | ||
11 | |||
12 | function help() { | ||
13 | cat <<HELP_TEXT | ||
14 | Usage: $0 --sstate-dir path --hashclient path --hashserver-address address \ | ||
15 | [--mark value] [--clean-db] [--threshold-age seconds] | ||
16 | |||
17 | Auxiliary script remove unused or no longer relevant entries from the hashequivalence database, based | ||
18 | on the files available on the sstate directory. | ||
19 | |||
20 | -h | --help) Show this help message and exit | ||
21 | -a | --hashserver-adress) bitbake-hashserver address | ||
22 | -c | --hashclient) Path to bitbake-hashclient | ||
23 | -m | --mark) Marker string to mark database entries | ||
24 | -s | --sstate-dir) Path to the sstate dir | ||
25 | -t | --threshold-age) Remove unused entries older than SECONDS old (default: 3600) | ||
26 | --clean-db) Remove all unmarked and unused entries from the database | ||
27 | HELP_TEXT | ||
28 | } | ||
29 | |||
30 | function argument_parser() { | ||
31 | while [ $# -gt 0 ]; do | ||
32 | case "$1" in | ||
33 | -h | --help) help; exit 0 ;; | ||
34 | -a | --hashserver-address) BB_HASHSERVER="$2"; shift ;; | ||
35 | -c | --hashclient) BB_HASHCLIENT="$2"; shift ;; | ||
36 | -m | --mark) ALIVE_DB_MARK="$2"; shift ;; | ||
37 | -s | --sstate-dir) SSTATE_DIR="$2"; shift ;; | ||
38 | -t | --threshold-age) THRESHOLD_AGE="$2"; shift ;; | ||
39 | --clean-db) CLEAN_DB="true";; | ||
40 | *) | ||
41 | echo "Argument '$1' is not supported" >&2 | ||
42 | help >&2 | ||
43 | exit 1 | ||
44 | ;; | ||
45 | esac | ||
46 | shift | ||
47 | done | ||
48 | |||
49 | function validate_mandatory_argument() { | ||
50 | local var_value="$1" | ||
51 | local error_message="$2" | ||
52 | |||
53 | if [ -z "$var_value" ]; then | ||
54 | echo "$error_message" | ||
55 | help >&2 | ||
56 | exit 1 | ||
57 | fi | ||
58 | } | ||
59 | |||
60 | validate_mandatory_argument "$SSTATE_DIR" "Please provide the path to the sstate dir." | ||
61 | validate_mandatory_argument "$BB_HASHCLIENT" "Please provide the path to bitbake-hashclient." | ||
62 | validate_mandatory_argument "$BB_HASHSERVER" "Please provide the address of bitbake-hashserver." | ||
63 | } | ||
64 | |||
65 | # -- main code -- | ||
66 | argument_parser $@ | ||
67 | |||
68 | # Mark all db sstate hashes | ||
69 | find "$SSTATE_DIR" -name "*.tar.zst" | \ | ||
70 | sed 's/.*:\([^_]*\)_.*/unihash \1/' | \ | ||
71 | $BB_HASHCLIENT --address "$BB_HASHSERVER" gc-mark-stream "$ALIVE_DB_MARK" | ||
72 | |||
73 | # Remove unmarked and unused entries | ||
74 | if [ "$CLEAN_DB" = "true" ]; then | ||
75 | $BB_HASHCLIENT --address "$BB_HASHSERVER" gc-sweep "$ALIVE_DB_MARK" | ||
76 | $BB_HASHCLIENT --address "$BB_HASHSERVER" clean-unused "$THRESHOLD_AGE" | ||
77 | fi | ||