Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //init
- parse_str(implode('&', array_slice($argv, 1)), $_GET);
- $error = array();
- $lPrefix = '/home/hozza/Sites/';
- $archiveLocation = '/home/hozza/Backups/';
- $log_stem = '/tmp/' . time() . '_'; // ie: /tmp/1357581737_
- $lfOutfile = $log_stem . 'lftp.log';
- $tarOutfile = $log_stem . 'tar.log';
- $lDir = isset($_GET['l']) ? $_GET['l'] : $error[] = 'Local Directory Required';
- $rDir = isset($_GET['r']) ? $_GET['r'] : $error[] = 'Remote Directory Required';
- $bookmark = isset($_GET['b']) ? $_GET['b'] : $error[] = 'lftp Bookmark Required';
- //Check for args
- if(count($error) == 0) {
- $archiveName = end(explode('/', $lDir)) . '_' . date('Y-m-d_H-i');
- //Validate local dir
- if(is_dir($lPrefix . $lDir)) {
- //preserve Sublime Text 2 config SFTP files
- $ST2_SFTP_conf = false;
- if(file_exists($lPrefix . $lDir . '/sftp-config.json')) {
- $ST2_SFTP_conf = file_get_contents($lPrefix . $lDir . '/sftp-config.json');
- unlink($lPrefix . $lDir . '/sftp-config.json');
- }
- shell_exec('lftp -e "mirror -e -p --parallel=10 --script=' . $archiveLocation . 'logs/' . $archiveName . '.txt ' . $rDir . '/ ' . $lPrefix . $lDir . '/; exit top" ' . $bookmark . ' | tee ' . $lfOutfile . ' 1>&2');
- shell_exec('cd ' . $lPrefix . ' && tar -czf ' . $archiveLocation . $archiveName . '.tar.gz ' . $lDir . ' | tee ' . $tarOutfile . ' 1>&2');
- $lfOut = file_get_contents($lfOutfile);
- $tarOut = file_get_contents($tarOutfile);
- // remove tmp files
- unlink($lfOutfile);
- unlink($tarOutfile);
- //Output completion or errors
- shell_exec('notify-send -i gnome-network-properties -t 0 "Mirror & Archive ' . $bookmark . ' Complete" "' . $archiveName . '\n\n' . $lfOut . $tarOut . '"');
- //put back ST2 SFTP conf
- if($ST2_SFTP_conf != false) file_put_contents($lPrefix . $lDir . '/sftp-config.json', $ST2_SFTP_conf);
- exit;
- }
- else shell_exec('notify-send -i error -t 0 "Mirror & Archive Error" "' . date('Y-m-d') . ' ' . date('H-i') . '\n' . $lDir . ' \n Does not exist! D:"');
- }
- else shell_exec('notify-send -i error -t 0 "Mirror & Archive Error" "' . date('Y-m-d') . ' ' . date('H-i') . '\n' . implode('\n', $error) . '"');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement