Beispiel #1
0
func InsertS3HistoryCopyFromS3(f S3FileHistory) (err error) {
	address := `127.0.0.1`
	sq := fmt.Sprintf(`INSERT INTO backups.file_history(cluster_id, dbname, node, file_name, action, status, duration, params) VALUES ('%s','%s','%s','%s','%s','%s',%d,'{"source":"%s", "target":"%s", "size":"%d", "bucket":"%s"}')`, globals.ClusterID, f.DBName, f.Node, f.FileName, `CopyFromS3`, f.Status, f.Duration, f.Source, f.Target, f.Size, f.Bucket)
	err = rdpgpg.ExecQuery(address, sq)
	if err != nil {
		log.Error(fmt.Sprintf("history.insertHistory() backup.S3FileHistory  Error inserting record into backups.file_history, running query: %s ! %s", sq, err))
	}
	return
}
Beispiel #2
0
func InsertRestoreHistory(f BackupFileHistory) (err error) {
	address := `127.0.0.1`
	sq := fmt.Sprintf(`INSERT INTO backups.file_history(cluster_id, dbname, node, file_name, action, status, duration, params) VALUES ('%s','%s','%s','%s','%s','%s',%d,'{"location":"%s","dbname":"%s","node":"%s","cluster_id":"%s"}')`, globals.ClusterID, f.DBName, f.Node, f.BackupFile, `RestoreBackup`, f.Status, f.Duration, f.BackupPathAndFile, f.DBName, f.Node, globals.ClusterID)
	err = rdpgpg.ExecQuery(address, sq)
	if err != nil {
		log.Error(fmt.Sprintf("history.InsertRestoreHistory() Error inserting record into backups.file_history, running query: %s ! %s", sq, err))
	}
	return
}
Beispiel #3
0
//DeleteBackupHistory - Responsible for deleting records from backups.file_history
//older than the value in rdpg.config.key = defaultDaysToKeepFileHistory
func DeleteBackupHistory() (err error) {
	daysToKeep, err := config.GetValue(`defaultDaysToKeepFileHistory`)
	log.Trace(fmt.Sprintf("tasks.DeleteBackupHistory() Keeping %s days of file history in backups.file_history", daysToKeep))

	address := `127.0.0.1`
	sq := fmt.Sprintf(`DELETE FROM backups.file_history WHERE created_at < NOW() - '%s days'::interval; `, daysToKeep)

	err = rdpgpg.ExecQuery(address, sq)
	if err != nil {
		log.Error(fmt.Sprintf(`history.DeleteBackupHistory() Error when running query %s ! %s`, sq, err))
	}
	return
}
//DeleteFile - Delete a file from the operating system
func (t *Task) DeleteFile() (err error) {
	taskParams := []byte(t.Data)
	fm := S3FileMetadata{}
	err = json.Unmarshal(taskParams, &fm)
	if err != nil {
		log.Error(fmt.Sprintf("tasks.DeleteFile() json.Unmarshal() ! %s", err))
	}
	log.Trace(fmt.Sprintf(`tasks.DeleteFile() Attempting to delete file "%s" `, fm.Location))
	err = os.Remove(fm.Location)
	if err != nil {
		log.Error(fmt.Sprintf(`tasks.DeleteFile() Attempted to delete file "%s" ! %s`, fm.Location, err))
	} else {
		//As long as the file was deleted, update the history record
		address := `127.0.0.1`
		sq := fmt.Sprintf(`UPDATE backups.file_history SET removed_at = CURRENT_TIMESTAMP WHERE params::text = '%s'`, t.Data)
		err = rdpgpg.ExecQuery(address, sq)
		if err != nil {
			log.Error(fmt.Sprintf(`tasks.DeleteFile() Attempted to update backups.file_history using query <<<%s>>> ! %s`, sq, err))
		}

	}

	return
}