Необходимо сделать комбинацию ответа Kristo и MSN:
// Note: Using the pre-increment operator is preferred for iterators because
// there can be a performance gain.
//
// Note: As long as you are iterating from beginning to end, without inserting
// along the way you can safely save end once; otherwise get it at the
// top of each loop.
std::list< item * >::iterator iter = items.begin();
std::list< item * >::iterator end = items.end();
while (iter != end)
{
item * pItem = *iter;
if (pItem->update() == true)
{
other_code_involving(pItem);
++iter;
}
else
{
// BTW, who is deleting pItem, a.k.a. (*iter)?
iter = items.erase(iter);
}
}
, Конечно, самое эффективное и SuperCool® STL savy вещь был бы чем-то вроде этого:
// This implementation of update executes other_code_involving(Item *) if
// this instance needs updating.
//
// This method returns true if this still needs future updates.
//
bool Item::update(void)
{
if (m_needsUpdates == true)
{
m_needsUpdates = other_code_involving(this);
}
return (m_needsUpdates);
}
// This call does everything the previous loop did!!! (Including the fact
// that it isn't deleting the items that are erased!)
items.remove_if(std::not1(std::mem_fun(&Item::update)));
Вы можете легко создать сценарий, который сделает это за вас.
EC2_CERT
и EC2_PRIVATE_KEY
, чтобы иметь возможность использовать инструменты API ec2-describe-snapshots
Результаты выглядят примерно так:
SNAPSHOT snap-xxxxxxxx vol-xxxxxxxx completed 2009-08-26T07:39:33+0000 100%
Затем вы можете сделать некоторый анализ дат и сортировка и начало удаления старых снимков.
ПРИМЕЧАНИЕ: я не знаю, можем ли мы доверять порядку сортировки, но я никогда не видел, чтобы сортировка выполнялась иначе, чем от старых к новейшим.
Чтобы удалить моментальный снимок, используйте ec2-delete-snapshot snap-xxxxxxxx
.
Остальное я оставляю вам в виде простого сценария Bash, который вы можете вызывать из cron ежедневно или сколько угодно раз.
Я нашел это, надеюсь, это поможет:
ec2-describe-snapshots | sort -r -k 5 | sed 1,6d | awk '{print "Deleting snapshot: " $2}'; system("ec2-delete-snapshot " $2)'
См .: Массовое удаление снимков EBS из командной строки (практическое руководство).