Upload attempts

This commit is contained in:
fogelito
2023-09-06 17:15:07 +03:00
parent faf9b42f9d
commit a7c6674a83
+7 -9
View File
@@ -16,12 +16,12 @@ use Utopia\Validator\Text;
class Backup extends Action
{
public const BACKUPS_PATH = '/backups';
public const BACKUP_INTERVAL_SECONDS = 60 * 60 * 4; // 4 hours;
//public const BACKUP_INTERVAL_SECONDS = 100;
//public const BACKUP_INTERVAL_SECONDS = 60 * 60 * 4; // 4 hours;
public const BACKUP_INTERVAL_SECONDS = 100;
public const COMPRESS_ALGORITHM = 'zstd'; // https://www.percona.com/blog/get-your-backup-to-half-of-its-size-introducing-zstd-support-in-percona-xtrabackup/
public const CLEANUP_LOCAL_FILES_SECONDS = 60 * 60 * 24 * 1; // 2 days?
public const CLEANUP_CLOUD_FILES_SECONDS = 60 * 60 * 24 * 1; // 14 days?;
public const UPLOAD_CHUNK_SIZE = 20 * 1024 * 1024; // Must be greater than 5MB;
public const UPLOAD_CHUNK_SIZE = 5 * 1024 * 1024; // Must be greater than 5MB;
protected string $filename;
protected ?DSN $dsn = null;
protected ?string $database = null;
@@ -113,7 +113,7 @@ class Backup extends Action
$local = new Local(self::BACKUPS_PATH . '/' . $this->database . '/full');
$local->setTransferChunkSize(self::UPLOAD_CHUNK_SIZE);
//$this->fullBackup($local);
$this->fullBackup($local);
$max = 1;
$i = 0;
@@ -121,11 +121,10 @@ class Backup extends Action
$i++;
try {
$this->upload($local);
break; // exit while
break;
} catch (Exception $e) {
if ($i <= $max) {
Console::warning($e->getMessage() . ' (' . $i . ' attempt)');
sleep(1);
} else {
throw new Exception($e->getMessage());
}
@@ -286,14 +285,13 @@ class Backup extends Action
return false;
}
$now = new \DateTime();
[$year, $month, $day, $hour, $minute, $second] = explode('_', $item);
$date = $year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second;
try {
$now = new \DateTime();
$backupDate = new \DateTime($date);
$difference = $now->getTimestamp() - $backupDate->getTimestamp();
if ($difference > $seconds) {
if (($now->getTimestamp() - $backupDate->getTimestamp()) > $seconds) {
return true;
}
} catch (Exception $e) {