GitHub user nxsbi added a comment to the discussion: Delete Templates from 
specific secondary storages

For anyone else trying to do this - As of 4.19.0.1, if you want to delete the 
secondary storage (assuming you have 2 or more secondary storage) that has 
templates stored on it, I followed the below steps. Note that you would want to 
move all your snapshots to other secondary storage beforehand. 

1. Identify the ID for the image store to be deleted. I simply ran the query 
below and manually noted it down. 

`select * from image_store where name = 'name of secondary store to be 
deleted';`

2. Verify that all templates are available on the other secondary storage. - 
NOTE I did not have any missing ones so did not have to address this issue, but 
if you have any missing ones, you will need to explore how to copy them over to 
the other image store. 

```
-- Identify templates that only exist in the secondary store to be deleted

SELECT DISTINCT tsr1.template_id
FROM template_store_ref  tsr1
WHERE tsr1.download_state = 'DOWNLOADED'
  AND tsr1.state = 'Ready'
  AND tsr1.store_id = <your_store_id_to_be_deleted>
  AND NOT EXISTS (
    SELECT 1
    FROM template_store_ref  tsr2
    WHERE tsr2.download_state = 'DOWNLOADED'
      AND tsr2.state = 'Ready'
      AND tsr2.store_id in (<your_store_id_that_will_not_be_deleted>) 
      AND tsr2.template_id = tsr1.template_id
  );
```

3. Delete the records from tempalte_store_ref

```
-- Take a backup
create table template_store_ref_backup as select * from template_store_ref;
-- Delete the records
delete from template_store_ref where store_id = <your_store_id_to_be_deleted>;

```
4. Go to the UI, and set the Secondary Store to read only, 

5. From UI, Delete the secondary Store




GitHub link: 
https://github.com/apache/cloudstack/discussions/9229#discussioncomment-9907095

----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscr...@cloudstack.apache.org

Reply via email to