-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Swapnil Mhamane <[email protected]>
- Loading branch information
Swapnil Mhamane
committed
Jun 5, 2018
1 parent
819788e
commit 6129c45
Showing
12 changed files
with
180 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) 2018 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package snapshotter | ||
|
||
import ( | ||
"path" | ||
"time" | ||
|
||
"github.com/gardener/etcd-backup-restore/pkg/snapstore" | ||
) | ||
|
||
// GarbageCollector basically consider the older backups as garbage and deletes it | ||
func (ssr *Snapshotter) GarbageCollector(stopCh <-chan bool) { | ||
for { | ||
select { | ||
case <-stopCh: | ||
return | ||
case <-time.After(ssr.garbageCollectionPeriodSeconds * time.Second): | ||
|
||
ssr.logger.Infoln("GC: Executing garbage collection...") | ||
snapList, err := ssr.store.List() | ||
if err != nil { | ||
ssr.logger.Warnf("GC: Failed to list snapshots: %v", err) | ||
continue | ||
} | ||
|
||
snapLen := len(snapList) | ||
var snapStreamIndexList []int | ||
snapStreamIndexList = append(snapStreamIndexList, 0) | ||
for index := 1; index < snapLen; index++ { | ||
if snapList[index].Kind == snapstore.SnapshotKindFull { | ||
snapStreamIndexList = append(snapStreamIndexList, index) | ||
} | ||
} | ||
|
||
for snapStreamIndex := 0; snapStreamIndex < len(snapStreamIndexList)-ssr.maxBackups; snapStreamIndex++ { | ||
for i := snapStreamIndexList[snapStreamIndex+1] - 1; i >= snapStreamIndex; i-- { | ||
ssr.logger.Infof("Deleting old snapshot: %s", path.Join(snapList[i].SnapDir, snapList[i].SnapName)) | ||
if err := ssr.store.Delete(*snapList[i]); err != nil { | ||
ssr.logger.Warnf("Failed to delete snapshot %s: %v", path.Join(snapList[i].SnapDir, snapList[i].SnapName), err) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.