To back up a git repo, is there any reason why I couldn't just run a cron like this?:
/usr/bin/tar -Pzcf git_backup.tar.gz repo.git && /usr/bin/scp git_backup.tar.gz me@other-server:/home/backup
If something happened to all other copies I could use the most recent, just tar -xzf into it's original place, clone, push, pull etc? Seems like it should be okay but I'm not 100% sure. Note: I've seen other answers involving git clone or using --mirror but this seems more straightforward. Those are still options if the answers indicate it would be better.
---------------- EDIT -----------------
Here's the script I ended up creating:
#!/usr/bin/php -q
<?php
/**
* Backup git on this box and copy it around
*
* cron:
* 1 2 * * * /usr/bin/php /home/sysadmin/files/shared/git_backup.php REPO 2> /dev/null
*
* @package scripts
* @author Hans Anderson <handerson@>
*/
list ( $dir, ) = explode ( '/files/', __FILE__ ); require_once ( "{$dir}/files/bootstrap.php" );
$email = $cfg['GIT_BACKUP']['email_errors_to'];
$copy_hosts = explode(',', $cfg['GIT_BACKUP']['hosts']);
if ( !isset ($argv[1]) ) exit;
$repo = $argv[1];
$date = date ( 'Y-m-d-H' );
$user = `whoami`; $user = trim($user);
$repf = "/newdisk/git/{$repo}.git";
$bndl = "/newdisk/backup/{$repo}/git/git-{$repo}-{$date}.bndl";
chdir($repf);
$exec = "/usr/bin/git bundle create $bndl --all";
exec ( "$exec", $error, $return );
if ( $return <> 0 ) // bad
{
mail ( $email, "{$user} GIT Backup Failure [{$repo}]!", __FILE__ . "\nFailure to dump.\nCmd: $exec\nError: $error" );
}
foreach ( $copy_hosts as $host )
{
$exec = "/usr/bin/scp -q {$bndl} sysadmin@{$host}:/home/sysadmin/data/backup/$repo/git";
exec ( $exec, $error, $return );
if ( $return <> 0 )
{
mail ( $email, "{$user} GIT Backup Failure [{$repo}]!", __FILE__ . "\nFailure to copy to dbs1.\nCmd: $exec\nError: " . implode ( "\n", $error ) . "\n\nReturn:" . implode ( "\n", $return ) );
}
}