Skip to content

Instantly share code, notes, and snippets.

@psychoticbeef
Created May 30, 2016 18:41
Show Gist options
  • Save psychoticbeef/bd543b5c1a323320194cbd9f202d07b2 to your computer and use it in GitHub Desktop.
Save psychoticbeef/bd543b5c1a323320194cbd9f202d07b2 to your computer and use it in GitHub Desktop.
convert ACTS / tarsnap-generations style backups to tarsnapper style backups
<?php
$machine = 'mycomputername';
$max_cmd_len = intval(shell_exec('getconf ARG_MAX'));
$commands = array();
$commands_del = array();
$cur_command = '';
$cur_command_del = ' -d ';
$f = file_get_contents('archives');
$lines = explode(PHP_EOL, $f);
foreach ($lines as $line) {
$parts = explode('_', $line);
if (count($parts) != 2) continue;
$parts_l = explode('-', $parts[0]);
$parts_r = explode('-', $parts[1]);
if ($parts_l[0] != $machine) continue;
$new_name = $parts_r[1] . '-' . $parts_l[2] . $parts_l[3] . $parts_l[4] . '-' . str_replace(':', '', $parts_r[0]);
$new_command = " -c -f $new_name @@$line";
$new_command_del = " -f $line";
$commands []= $new_command;
//if (strlen($cur_command) + strlen($new_command) < $max_cmd_len) {
// $cur_command .= $new_command;
//} else {
// $commands []= $cur_command;
// $cur_command = $new_command;
//}
if (strlen($cur_command_del) + strlen($new_command_del) < $max_cmd_len) {
$cur_command_del .= $new_command_del;
} else {
$commands []= $cur_command_del;
$cur_command_del = $new_command_del;
}
//echo $new_name . PHP_EOL;
}
$commands []= $cur_command;
$commands []= $cur_command_del;
foreach ($commands as $command) echo "tarsnap $command" . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment