Skip to content

Instantly share code, notes, and snippets.

@Vampire
Created December 19, 2012 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vampire/4336924 to your computer and use it in GitHub Desktop.
Save Vampire/4336924 to your computer and use it in GitHub Desktop.
--- /usr/bin/happ-backup 2012-09-26 17:44:20.000000000 +0000
+++ happ-backup 2012-12-19 14:14:21.055611292 +0000
@@ -1,18 +1,25 @@
#!/usr/bin/perl -w
-# happ-backup [user|project] [db|file] [app]
+# happ-backup [-q] (user|project) (db|file) <app>
use JSON;
my ($user) = getpwuid($<);
my ($group) = getgrgid($();
+my $quiet = 0;
# Quick input validation
-unless(@ARGV == 3 && $ARGV[0] =~ m/^(user|project)$/ && $ARGV[1] =~ m/^(db|file)$/) {
+unless(@ARGV >= 3 && @ARGV <= 4) {
+ &usage();
+}
+if($ARGV[0] eq '-q') {
+ $quiet = 1;
+}
+unless($ARGV[0 + $quiet] =~ m/^(user|project)$/ && $ARGV[1 + $quiet] =~ m/^(db|file)$/) {
&usage();
}
# Setup variables for later use
-my $type = lc($ARGV[0]);
-my $content = lc($ARGV[1]);
-my $app = lc($ARGV[2]);
+my $type = lc($ARGV[0 + $quiet]);
+my $content = lc($ARGV[1 + $quiet]);
+my $app = lc($ARGV[2 + $quiet]);
my $instance;
my $subpath;
my ($xx,$x);
@@ -28,7 +35,7 @@
}
my $conf_path = "/home/$app/conf/$type/$x/$xx/$instance/sf.json";
-my $content_path = "/home/$app/content/$type/$x/$xx/$instance";
+my $content_path = "home/$app/content/$type/$x/$xx/$instance";
# Make sure the instance exists and config file is readable...
unless(-e $conf_path) {
@@ -57,27 +64,25 @@
my $ret = system('/usr/bin/mysqldump','-n','-u',$db_user,'-h',$db_host,"-p$db_pass",'-r',$file,$db_name) >> 8;
unless($ret == 0) {
die "Error dumping database to $file: $ret\n";
- } else {
+ } elsif(!$quiet) {
print "Database successfully dumped to: $file\n";
}
} else {
+ my $ret = system('/bin/tar', ($quiet ? '' : 'v') . 'czf', $file, '-C', '/', $content_path) >> 8;
unless($ret == 0) {
die "Error creating content tarball: $file\n";
- } else {
+ } elsif(!$quiet) {
print "Tarball of $app file contents in: $file\n";
}
-
}
-
exit 0;
sub usage {
- print "Usage: $0 [user|project] [db|file] [app]\n
-App is one of:
+ die "Usage: $0 [-q] (user|project) (db|file) <app>\n
+app is one of:
aguestbook
codestriker
dotproject
@@ -93,7 +98,5 @@
taskfreak
trac
wordpress\n";
-
- exit;
}
@Vampire
Copy link
Author

Vampire commented Dec 19, 2012

You can also take it from /home/users/v/va/vampire0/happ-backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment