File: oci-compute-node-image-cache-cleaner

package info (click to toggle)
openstack-cluster-installer 43.0.19
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,540 kB
  • sloc: php: 19,150; sh: 18,091; ruby: 75; makefile: 31; xml: 8
file content (25 lines) | stat: -rwxr-xr-x 921 bytes parent folder | download | duplicates (3)
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
#!/bin/sh

set -e

if [ -d /var/lib/nova/instances/_base/ ] && [ -n "$(ls -A /var/lib/nova/instances/_base/)" ] ; then
	cd /var/lib/nova/instances/_base/

	BACKING_LIST=$(mktemp -t $(basename $0).XXXXXX)

	# Lookup all base image if they have a backing image
	find -type f | xargs -n1 qemu-img info | grep backing | sed -e 's/.*file: //' -e 's/ .*//' >${BACKING_LIST}

	# Lookup all running instances if they have a backing image
	find /var/lib/nova/instances -type f -iname disk | xargs -n1 qemu-img info | grep backing | sed -e 's/.*file: //' -e 's/ .*//' >>${BACKING_LIST}

	# Add them in an ignore list for find
	DO_NOT_DELETE="! -name . "
	for i in $(cat ${${BACKING_LIST} | sort -u) ; do
		DO_NOT_DELETE="${DO_NOT_DELETE} -a ! -name "$(basename $i)
	done
	rm -f ${BACKING_LIST}

	# Delete all non-backing image older than 6h
	find /var/lib/nova/instances/_base/ -mmin +360 -type f \( ${DO_NOT_DELETE} \) -delete
fi