backup.php 592 Bytes
Newer Older
dmorley's avatar
backup  
dmorley committed
1
<?php
2 3
require_once __DIR__ . '/../config.php';

dmorley's avatar
changes  
dmorley committed
4
$keep = (60 * 60 * 6) * 1; 
5 6 7 8 9 10
$dump_date = date("Ymd_Hs");
$file_name = $backup_dir . "/dump_" . $dump_date . ".sql";
system("export PGPASSWORD=$pgpass && $pg_dump_dir/pg_dump --username=$pguser $pgdb >> $file_name");
echo "pg backup of $pgdb made";
$dirh = dir($backup_dir);
while($entry = $dirh->read()) {
dmorley's avatar
cleanup  
dmorley committed
11 12 13 14 15 16 17
  $old_file_time = (date("U") - $keep);
  $file_created = filectime("$backup_dir/$entry");
  if ($file_created < $old_file_time && !is_dir($entry)) {
    if(unlink("$backup_dir/$entry")) {
      echo "Cleaned up old backups";
    }
  }
dmorley's avatar
backup  
dmorley committed
18
}