func main() {

	_, err := io.WriteString(file, "backupcommand running....\n")
	if err != nil {
		log.Println(err.Error())
	}

	defer closeLog()

	getEnvVars()
	s := backup.BackupStatus{}
	eDuration := time.Since(startTime)
	s.StartTime = startTime.String()
	s.StartTime = startTime.String()
	s.ElapsedTime = eDuration.String()
	s.Status = "initializing"
	s.BackupSize = du()
	sendStats(s)

	//kick off stats reporting in a separate thread
	go stats("hi")

	io.WriteString(file, "giving DNS time to register the backup job....sleeping for 7 secs")
	time.Sleep(7000 * time.Millisecond)

	//perform the backup
	backupfunc("end")

	//send final stats to backup
	finalstats("end")

}
//report stats back to the cpm-admin for this backup job
func finalstats(str string) {

	//connect to backupserver on cpm-admin
	//send stats to backup
	stats := backup.BackupStatus{}
	eDuration := time.Since(startTime)
	stats.StartTime = startTime.String()
	stats.ElapsedTime = eDuration.String()
	stats.Status = "completed"
	stats.BackupSize = du()

	sendStats(stats)
	io.WriteString(file, "final stats here\n")
}
func sendStats(stats backup.BackupStatus) error {
	stats.ContainerName = backupContainerName
	stats.ServerName = backupServerName
	stats.ScheduleID = scheduleID
	stats.ServerIP = backupServerIP
	stats.ProfileName = backupProfileName
	stats.Path = backupPath
	stats.BackupName = backupHost
	stats.ID = StatusID

	var err error
	if StatusID != "" {
		_, err = backup.UpdateStatusClient(backupAgentURL, stats)
	} else {
		StatusID, err = backup.AddStatusClient(backupAgentURL, stats)
	}
	if err != nil {
		io.WriteString(file, "error in adding status:"+err.Error()+"\n")
		return err
	}

	//send to backup
	io.WriteString(file, "elapsed time:"+stats.ElapsedTime+"\n")
	io.WriteString(file, "backupsize :"+stats.BackupSize+"\n")
	return nil
}
//report stats back to the cpm-admin for this backup job
func stats(str string) {

	for true {
		io.WriteString(file, "sending stats...\n")
		io.WriteString(file, "sleeping for 7 secs\n")
		time.Sleep(7000 * time.Millisecond)
		stats := backup.BackupStatus{}
		eDuration := time.Since(startTime)
		stats.StartTime = startTime.String()
		stats.StartTime = startTime.String()
		stats.ElapsedTime = eDuration.String()
		stats.Status = "running"
		stats.BackupSize = du()
		sendStats(stats)
	}
}