La segunda línea a continuación es un error tipográfico fatal, (probablemente estaba destinado a ser num="$num"
), pero la línea sería innecesaria si fuera correcta.
read num
num=num
Si el usuario ingresa el número "1" , la segunda línea lo cambia a la cadena no numérica -"num" . Lo que rompería todas las comprobaciones vinculadas a números a partir de entonces.
Para arreglar eso, simplemente elimine la segunda línea.
Для дальнейшего использования я использовал следующую логику. После интенсивных тестов он работает нормально. Тем не менее, мы высоко ценим лучшие ответы и идеи. Для справки см. также это обсуждение на zfs -список рассылки обсуждения .
for dataset in tree:
# If there is no snapshot for this dataset, make one...
if len(dataset['SNAPSHOTS']) == 0:
make_snapshot(dataset)
continue
# If nothing has been written, no snapshot is required.
if dataset['written'] == 0:
continue
# If written is north of 1 MByte, make a snapshot.
if dataset['written'] > (1024 ** 2):
make_snapshot(dataset)
continue
# If the dataset is not a filesystem and
# we got this far, make a snapshot.
if dataset['type'] == 'volume':
make_snapshot(dataset)
continue
# Only filesystems with less than 1 MByte written left.
# Let's look at the diff of the last snapshot.
diff_out = run_command([
'zfs', 'diff',
dataset['NAME'] + '@' + dataset['SNAPSHOTS'][-1]['NAME']
])
# If the diff is not empty, make a snapshot.
if len(diff_out.strip(' \t\n')) > 0:
make_snapshot(dataset)