← Back to team overview

mylvmbackup-discuss team mailing list archive

Re: precleanup problem

 

On Mon, 2009-08-24 at 17:43 +0400, Kirill Morozov wrote:
> i have a big problem.
> Second time at this week mylvmbackup hook "precleanup" has removed all  
> content of the server.

ouch.

> This is what i see on screen:
> ...
> backup-pos/backup-20090824_122832_mysql.pos
> backup-pos/backup-20090824_122832_mysql_my.cnf
> 81.6%
> 20090824 12:28:55 Info: DONE: create tar archive
> 20090824 12:28:55 Info: Running hook 'precleanup' as perl module.
> 
> /bin/rm: cannot remove directory `//usr/home': Device or resource busy
> 
> etc.
> 
> My /etc/mylvmbackup.conf is:
[...]
> #
> # File system specific options
> #
> [fs]
> xfs=0
> mountdir=/var/tmp/mylvmbackup/mnt/
> backupdir=/backup/
> relpath=/lib/mysql/

relpath should be relative, i.e. "lib/mysql", although it doesn't look
like mylvmbackup itself cares about the distinction, and it's probably
not relevant for your problem.

> I think the problem is in the precleanup hook perl package:
>         while($_ = readdir(DIR))
>         {
>                 next if /^\.{1,2}$/;
>                 my $path = "$dest/$_";
> 
>                 if(-d $path && int(-M $path) > $retention)
>                 {
>                         if(system("/bin/rm -rf $path") != 0)
>                         {
>                                 $errstr .= "Unable to prune $path: $!\n";
>                         }
>                 }
>         }
>         closedir DIR;
> 
> Why this hook tries to remove all content of the backup folder  
> "backupdir=/backup/"? I save another backups in the /backup directory,  
> not only mylvmbackup, i don't need to remove it.

you're supposed to specify a mylvmbackup specific directory for the
backup.  the default is "/var/tmp/mylvmbackup/backup".

I don't have the precleanup hook script here (what's its source?), but
that is definitely dangerous code.  if $path contains spaces, the shell
will split the argument.  e.g., "/backups/my . files/" will try to
delete "backups/my" which doesn't exist, then "." (current directory,
which is probably "/").  shouldn't be a problem for most people, but it
sure would be better to be paranoid about an "rm -rf" command run as
root.  the patch is simple:

-                       if(system("/bin/rm -rf $path") != 0)
+                       if(system("/bin/rm", "-rf", $path) != 0)


-- 
Kjetil T. Homme
Redpill Linpro AS - Changing the game




Follow ups

References