function walk_dirs($files, $backup_dirs, $path_prefix = '') { foreach ($backup_dirs as $bd) { if ($bd == '.' || $bd == '..') { continue; } $path_prefix = fix_path_end($path_prefix); $bd = "{$path_prefix}{$bd}"; if (is_file($bd)) { array_push($files, $bd); continue; } if (!is_dir($bd)) { continue; } $sres = scandir($bd); if ($sres === false) { echo "Cannot scan {$sres}\n"; } $files = walk_dirs($files, $sres, $bd); } return $files; }
} $stmt = $db->prepare("INSERT OR REPLACE INTO runinfo (date, value) VALUES (:date, :value) "); if (!$stmt) { die("Could not prepare runinfo\n"); } $stmt->bindValue(':date', $today); $stmt->bindValue(':value', $count); $stmt->execute(); $hostname = gethostname(); echo "plainbackup running on {$hostname} on " . date(DATE_RFC822) . "\n"; $archive_prefix = LOCAL_TMP_PREFIX . $today . '-' . sprintf('%03d', $count); if ($full_backup) { $archive_prefix .= '-full'; } $files = array(); $files = walk_dirs($files, $backup_dirs); $db->exec("CREATE TABLE IF NOT EXISTS file_to_hash(\n file TEXT UNIQUE NOT NULL,\n hash TEXT NOT NULL\n)"); $filelist = fopen(BACKUP_LIST, "w") or die("Unable to open file!"); $new_files = 0; $changed_files = 0; $unchanged_files = 0; foreach ($files as $f) { $hash = md5_file($f); if ($full_backup) { $new_files++; } else { $sel_stmt = $db->prepare('SELECT hash FROM file_to_hash WHERE file = :filename'); if (!$sel_stmt) { die("Could not prepare hash select for {$f}\n"); } $sel_stmt->bindValue(':filename', $f);