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

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