Page 1 of 1
Backup all files except tar
Posted: Wed Dec 15, 2010 7:44 am
by superdezign
I'm relatively new to Linux. I am using it on a dedicated server and am communicating with it via SSH. I am currently in the process of doing a server backup, re-image, and restore, since I accidentally removed Plesk and Horde webmail. The backup is being stored on a separate backup server. I have a few issues.
I was doing the backup last night of the directories that I wanted to save with an ftp pipe command using tar.
Code: Select all
ftp> put "|tar cvf /boot /root [...]" backup.tar.gz
Everything seemed to be going smoothly till it ran into a 7GB file, at which point my SSH connection was eventually severed due to inactivity. This brings me to my first question:
1. How can I verify the contents of a *.tar file?
I tried:
But, I got an error stating that the file could not be found. I verified that the file existed with
ls, so I'm not sure why I was getting that error.
My second question involves removing the current backup and trying to make another. However, this time I don't want to back up the backups. There are *.tar files on the server which are all backups of the folders that I'm going to be backing up.
2. How can I build a *.tar file of all files except files with a tar extension?
If it can't be done directly through tar but can be done through put, I am willing to transfer the files via put and then tar the files afterwards.
Any suggestions?? Oh, and by the way, hi everybody! Long time no see.
Re: Backup all files except tar
Posted: Wed Dec 15, 2010 8:26 am
by superdezign
Actually, considering I'm willing to throw these tar files away anyway, I may as well just delete them before making the backup. Simple answers never come to my mind. lol
Re: Backup all files except tar
Posted: Wed Dec 15, 2010 6:40 pm
by Doug G
man tar and you can find how to exclude files when creating a tar archive. And you'll see how to view the directory of the contents of an archive, etc.
Also if it's your ssh server there are keepalive settings that may prevent your connection dropping when transferring large files.
Re: Backup all files except tar
Posted: Fri Dec 17, 2010 8:03 am
by superdezign
Thanks for the reply. I did go through the man page like you suggested and learned a lot. Thanks.
As for the keepalive, I'm still trying to figure that out in PuTTy.
Re: Backup all files except tar
Posted: Fri Dec 17, 2010 12:25 pm
by VladSun
I have a Perl skeleton script that I use very often:
Code: Select all
#!/usr/bin/perl
use POSIX;
$SIG{INT} = $SIG{TERM} = 'dieHandler';
sub dieHandler
{
logger("Stopped ");
exit;
}
sub logger
{
my ($msg) = @_;
$now = strftime("%Y.%m.%d %R", localtime(time));
print STDOUT "\n".$now."\t".$msg;
}
sub demonize
{
defined (my $tpid = fork) or die "[-] Could not demonize";
if ($tpid)
{
exit;
}
else
{
POSIX::setsid() or die "[-] Could not demonize";
open STDOUT, '>>/var/log/my.log' or die "[-] Could not demonize";
open STDIN, '>>/var/log/my.log' or die "[-] Could not demonize";
}
}
print "\n[+] Going in background\n\n";
&demonize();
# Do whatever you want here ...
# E.g call a PHP script :
# `/path/myscript.php`;
This will detach your process from your TTY and put it in background, so even if you get disconnected the script will keep runing until it finishes its work.
PS: it's dEmonize indeed

No A
It kills its parent

Re: Backup all files except tar
Posted: Sun Dec 26, 2010 5:04 pm
by josh
How is that different than using the nohup command? Why did you roll your own solution instead?
Re: Backup all files except tar
Posted: Mon Dec 27, 2010 2:44 am
by VladSun
Works better

Does exactly what I want it to do.
Try it.
Re: Backup all files except tar
Posted: Mon Dec 27, 2010 2:45 pm
by josh
Could you explain? `nohup php myscript.php &` this makes my script run in the background and continue even after I log off SSH. What does your script do differently? Just wondering.
Re: Backup all files except tar
Posted: Tue Dec 28, 2010 4:42 am
by VladSun
You're right - you can do this by using nohup and you'll achieve almost the same result.
I use my skeleton mainly to run my tools at boot time (e.g. in rc.local / init.d scripts etc).
My skeleton won't wait for Enter to be pressed, won't write bogus messages to stdout (if you want so), won't create dummy nohup.out files (though with nohup you can redirect it). It will detach immediately from the TTY. It will put itself in the background without the need of passing the & argument.
Also most of my "bash" scripts are written in Perl - probably the best language for "bash" programming. Bash is powerful, but it's not my "type"
In one sentence - my skeleton is useful in case some repeated and continuous actions are to be performed. Whether you'll write a bash script with "nohup action params & > /log/log.txt" inside it or use this Perl skeleton would be your choice

Re: Backup all files except tar
Posted: Tue Dec 28, 2010 9:54 pm
by Doug G
screen is even more fun, you can detach and close your ssh session and your process continues, and then you can reconnect and re-attach to the process once you get logged back on.