Start adding the restore command

master
fstltna 2019-08-11 20:47:43 -07:00
parent 71e5570b39
commit 0e7108afee
3 changed files with 180 additions and 21 deletions

View File

@ -1,17 +1,19 @@
# Minetest Management Console (1.5.0)
# Minetest Management Console (1.6.0)
Allows you to manage your Minetest server with a text based GUI - Official support sites: [Official Github Repo](https://github.com/fstltna/MinetestManagementConsole) - [Official Forum](https://minecity.online/index.php/forum/management-console)
---
You will need to run cpan and install these modules:
- UI::Dialog
- Term::ReadKey
- Term::ANSIScreen
- cpan -i UI::Dialog
- cpan -i Term::ReadKey
- cpan -i Term::ANSIScreen
- cpan -i POSIX
- cpan -i Number::Bytes::Human
Run "mmc". If you need to change any settings after this, edit "~/.mmcrc" and make the desired changes. This can be done within mmc itself.
You also need to have my Minetest Startup Script and Minetest Backup Script installed.
I then suggest you add this directory (MinetestManagementConsole) into your path, so that you can just run "git pull" to upgrade to the latest version mmc as updates come out.
I then suggest you add this directory (MinetestManagementConsole) into your path, so that you can just run "git pull" to upgrade to the latest version of mmc as updates come out.

Binary file not shown.

189
mmc Executable file → Normal file
View File

@ -5,6 +5,8 @@ use warnings;
use UI::Dialog;
use Term::ReadKey;
use Term::ANSIScreen qw(cls);
use POSIX qw(strftime);
use Number::Bytes::Human qw(format_bytes parse_bytes);
my $FileEditor = "/bin/nano";
my $InitDName = "/etc/init.d/minetest";
@ -15,6 +17,8 @@ my $Logfile = "/root/minetest/debug.txt";
my $PlayersDir = "/root/minetest/worlds/world/players";
my $MinetestConf = "/root/minetest/minetest.conf";
my $MinetestWorld = "/root/minetest/worlds/world/world.mt";
my $BACKUP_DIR = "/root/backups";
my $RestoreCommand = "tar xvzf";
###################################################
# No changes below here
@ -22,7 +26,7 @@ my $MinetestWorld = "/root/minetest/worlds/world/world.mt";
my $MySettings = "$ENV{'HOME'}/.mmcrc";
my $MMC_ver = "1.5.0";
my $MMC_ver = "1.6.0";
my $Record = "false"; # Are results saved?
my $TempDir = "/tmp";
my $RobotName = "";
@ -30,6 +34,11 @@ my $BotVersion = "";
my $UserName = "";
my $ServerStatus = "foo";
if ($ENV{'EDITOR'})
{
$FileEditor = $ENV{'EDITOR'};
}
my $d = new UI::Dialog ( backtitle => "Minetest Management Console v$MMC_ver", height => 20, width => 65, listheight => 5,
order => [ 'ascii', 'cdialog', 'xdialog' ]);
@ -91,6 +100,18 @@ if (-f $MySettings)
{
$MinetestWorld = $Setting;
}
if ($Command eq "debugmode")
{
$DEBUG_MODE = $Setting;
}
if ($Command eq "backupdir")
{
$BACKUP_DIR = $Setting;
}
if ($Command eq "restorecommand")
{
$RestoreCommand = $Setting;
}
}
close($FH);
}
@ -98,15 +119,18 @@ else
{
# Store defaults
open (my $FH, ">", $MySettings) or die "Could not create default file '$MySettings' $!";
print $FH "fileeditor=/bin/nano\n";
print $FH "initdname=/etc/init.d/minetest\n";
print $FH "minetestdir=/root/minetest\n";
print $FH "backupcommand=/root/MineBackup/minebackup.pl\n";
print $FH "pagercommand=/usr/bin/less\n";
print $FH "logfile=/root/minetest/debug.txt\n";
print $FH "playerdir=/root/minetest/worlds/world/players\n";
print $FH "minetestconf=/root/minetest/minetest.conf\n";
print $FH "minetestworld=/root/minetest/worlds/world/world.mt\n";
print $FH "fileeditor=$FileEditor\n";
print $FH "initdname=$InitDName\n";
print $FH "minetestdir=$MINETESTDIR\n";
print $FH "backupcommand=$BackupCommand\n";
print $FH "pagercommand=$PagerCommand\n";
print $FH "logfile=$LogFile\n";
print $FH "playerdir=$PlayersDir\n";
print $FH "minetestconf=$MINETESTDIR/minetest.conf\n";
print $FH "minetestworld=$MINETESTDIR/worlds/world/world.mt\n";
print $FH "debugmode=$DEBUG_MODE\n";
print $FH "backupdir=$BACKUP_DIR\n";
print $FH "restorecommand=$RestoreCommand\n";
close($FH);
}
@ -127,6 +151,142 @@ sub CheckServerStatus
}
sub BackupToolsMenu
{
my $WantRespawn="ON";
CheckServerStatus();
if (-f "$MINETESTDIR/nostart")
{
$WantRespawn="OFF";
}
$menuselection = $d->menu( title => "Backup Tools Menu", text => "Server is $ServerStatus and respawn is $WantRespawn - Select one:",
list => [ '1', 'Run Backup',
'2', 'Restore Backup',
'q', 'Main Menu' ] );
}
sub GetWhichBackup
{
my $UsedFile = 0;
opendir(DIR, $BACKUP_DIR) or die $!;
my @file_list;
while ( my $file = readdir(DIR))
{
# We only want files
next unless (-f "$BACKUP_DIR/$file");
# Use a regular expression to find files ending in .tgz
next unless ($file =~ m/\.tgz$/);
push @file_list, "$BACKUP_DIR/$file";
}
closedir(DIR);
#print scalar @file_list;
system("clear");
print "Backup\tBackup Date\t\tSize\n";
for my $file (sort
{
my @a_stat = stat($a);
my @b_stat = stat($b);
$b_stat[8] <=> $a_stat[8];
} @file_list ) {
$UsedFile++;
my @stat = stat ("$file");
my $size = format_bytes($stat[7], bs => 1000);
print "$UsedFile\t" . strftime("%m/%d/%Y %H:%M:%S", localtime($stat[8])) . "\t$size ($file)\n";
};
#Ask user which one
while(-1)
{
print "Restore which backup? (1-5): ";
my $Chosen = <STDIN>;
chop ($Chosen);
if ((lc($Chosen) eq "q") || (lc($Chosen) eq "quit") || ($Chosen eq ""))
{
return "";
}
my $IntChosen = int($Chosen);
if (($IntChosen >= 1) && ($IntChosen <= 5))
{
return $Chosen;
}
}
}
sub DoRestore
{
my $WhichBackup = "";
# Get which backup they want
$WhichBackup = GetWhichBackup();
if ($WhichBackup eq "")
{
print "No backup selected\n";
print "Press Enter To Continue";
my $entered = <STDIN>;
return;
}
print "Using backup $WhichBackup...\n";
# Turn off respawn
PrintDebugCommand("touch $MINETESTDIR/nostart");
system("touch $MINETESTDIR/nostart");
# Kill the server process
print "Killing SBBS process, please wait...";
KillBBS();
sleep(10);
# Create new folder
print "Creating new folder, please wait...";
PrintDebugCommand("mkdir $MINETESTDIR-new");
system("mkdir $MINETESTDIR-new");
PrintDebugCommand("touch $MINETESTDIR-new/nostart");
system("touch $MINETESTDIR-new/nostart");
# Swap folders
print "Swapping folders, please wait...";
PrintDebugCommand("mv $MINETESTDIR $MINETESTDIR-keep");
system("mv $MINETESTDIR $MINETESTDIR-keep");
PrintDebugCommand("mv $MINETESTDIR-new $MINETESTDIR");
system("mv $MINETESTDIR-new $MINETESTDIR");
PrintDebugCommand("rm -r $MINETESTDIR-keep");
system("rm -r $MINETESTDIR-keep");
# Do the restore
chdir ("/");
PrintDebugCommand("$RESTORE_COMMAND $BACKUP_DIR/syncbackup-$WhichBackup.tgz");
system("$RESTORE_COMMAND $BACKUP_DIR/syncbackup-$WhichBackup.tgz");
unlink("$MINETESTDIR/nostart");
}
sub BackupTools
{
while (-1)
{
BackupToolsMenu();
if (($menuselection eq "CANCEL") || ($menuselection eq "ESC") || ($menuselection eq "") || ($menuselection eq "q") || ($menuselection eq "Q"))
{
return;
}
elsif ($menuselection eq "1")
{
# Run a backup
PrintDebugCommand("$BackupCommand");
system("$BackupCommand");
print "Press Enter To Continue";
my $entered = <STDIN>;
}
elsif ($menuselection eq "2")
{
# Do a restore
DoRestore();
print "Press Enter To Continue";
my $entered = <STDIN>;
}
}
}
sub MainMenu
{
my $WantRespawn="ON";
@ -144,7 +304,7 @@ sub MainMenu
'5', 'Turn Respawn On',
'6', 'Edit World Cfg',
'7', 'Edit minetest.conf',
'8', 'Run Backup',
'8', 'Backup / Restore',
'9', 'View Log',
'10', 'View Players',
'11', 'Edit Settings',
@ -203,11 +363,8 @@ while (-1)
}
elsif ($menuselection eq "8")
{
# Run a backup
system("clear");
system("$BackupCommand");
print "Press Enter To Continue";
my $entered = <STDIN>;
# Backup Menu
BackupTools();
}
elsif ($menuselection eq "9")
{