The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Exclude User from backups

Discussion in 'General Discussion' started by asmithjr, May 13, 2004.

  1. asmithjr

    asmithjr Well-Known Member

    Joined:
    Jun 13, 2003
    Messages:
    475
    Likes Received:
    1
    Trophy Points:
    18
    I did not find anything to allow me to exclude a user or users from the backups when using cpbackup so I made a couple modifications:

    1st. I create a file called nobackup that contains the users I do not want to backup. One per line.

    2nd. I created a script (I named mvuser): This script will take the users in my nobackup file, move them out of the /var/cpanel/users directory. This way when cpbackup runs it will not backup those users since it uses the users from the /var/cpanel/users directory.

    3rd. This is the way I implemented it. I modified the cpbackup script but you could simple execute the mvuser script before and after the backups are completed.

    Code:
    #!/bin/sh
    
    # mvuser - script to move users from /var/cpanel/users during backup
    # process. We move uses out of directory we do not want to backup
    # Script takes 1 argument. Either in or out.
    
    # Place the following two lines below the following line /scripts/cpbackup
    # close to line 280. Remember to remove the comment on the system line
    # sub backupaccts {
    # Move the users in nobackup back to users directory. See mvuser
    # system("mvuser out");
    
    # And the following two lines before the closing "}" for the sub backupaccts
    # close to line 346. Remember to remove the comment on the system line
    # Move the users in nobackup back to users directory. See mvuser
    # system("mvuser in");
    
    USERS=nobackup     # list of users not to backup
    
    DIR=/var/cpanel/users
    TMPDIR=/tmp
    
    case $1 in
            out) # move the user file out temporarily
                    for i in `cat $USERS`
                    do
                            mv $DIR/$i $TMPDIR
                            echo "mv $DIR/$i $TMPDIR"
                    done
            ;;
            in) # move the user file back to DIR
                    for i in `cat $USERS`
                    do
                            mv $TMPDIR/$i $DIR
                            chmod 644 $DIR/$i
                            chown cpanel:root $DIR/$i
                    done
            ;;
            *) echo "Usage: mvuser [in/out] ";;
    esac
    
    #
    # End
    #
    
    Note: the mvuser script takes argument in and out. Out to move the users from the /var/cpanel/users and in to move them back in. So I simply have the cpbackup script execute mvuser out before I start the backup of the users and mvuser in when the backups are complete.
     
Loading...

Share This Page