Jump to content

DontCare

Inactive Member
  • Posts

    34
  • Joined

  • Last visited

  • Feedback

    0%

Posts posted by DontCare

  1. Hey, few month ago I've found sh scrip for backups and bit modified it (usable only for linux/unix).

    So here is a short tutorial:

     

    1) Make next folders on your server:

    /backup 

    /backup/metin2

     

    2) Make file /backup/backup.sh and put in it next:

    #!/bin/bash
    PROJNAME=metin2
    CHARSET=utf8
    DBNAME01=account
    DBNAME02=common
    DBNAME03=player
    DBFILENAME01=account
    DBFILENAME02=common
    DBFILENAME03=player
    HOST=localhost
    USER=db_user
    PASSWD="db_pass"
    DATADIR=/backup/metin2
    SRCFILES=/home/game
    PREFIX=`date +%F`
    echo $PASSWD
    #start backup
    echo "[--------------------------------[`date +%F--%H-%M`]--------------------------------]"
    echo "[--START!--][`date +%F--%H-%M`] Run the backup script..."
    mkdir $DATADIR/$PREFIX 2> /dev/null
    echo "[+---------][`date +%F--%H-%M`] Generate a database backup..."
    #MySQL dump
    mysqldump --user=$USER --host=$HOST --password="$PASSWD" --default-character-set=$CHARSET $DBNAME01 > $DATADIR/$PREFIX/$DBFILENAME01-`date +%F-%H-%M`.sql
    mysqldump --user=$USER --host=$HOST --password="$PASSWD" --default-character-set=$CHARSET $DBNAME02 > $DATADIR/$PREFIX/$DBFILENAME02-`date +%F-%H-%M`.sql
    mysqldump --user=$USER --host=$HOST --password="$PASSWD" --default-character-set=$CHARSET $DBNAME03 > $DATADIR/$PREFIX/$DBFILENAME03-`date +%F-%H-%M`.sql
    if [[ $? -gt 0 ]];then
    echo "[----------][`date +%F--%H-%M`] Aborted. Generate database backup failed."
    exit 1
    fi
    echo "[++--------][`date +%F--%H-%M`] Backup database - successfull."
    #Src dump
    echo "[+++-------][`date +%F--%H-%M`] Copy the source code project [$PROJNAME]..."
    tar -czpf $DATADIR/$PREFIX/$PROJNAME-`date +%F-%H-%M`.tar.gz $SRCFILES 2> /dev/null
    if [[ $? -gt 0 ]];then
    echo "[----------][`date +%F--%H-%M`] Aborted. Copying the source code failed."
    exit 1
    fi
    echo "[++++------][`date +%F--%H-%M`] Copy the source code project successfull."
    echo "[+++++-----][`date +%F--%H-%M`] Prepare zip file $PROJNAME-$PREFIX.zip..."
    zip -r $DATADIR/$PROJNAME-$PREFIX.zip $DATADIR/$PREFIX
    if [[ $? -gt 0 ]];then
    echo "[----------][`date +%F--%H-%M`] Aborted. Make zip file failed."
    exit 1
    fi
    echo "[++++++----][`date +%F--%H-%M`] Zip file $PROJNAME-$PREFIX.zip finished."
    
    echo "[+++++++---][`date +%F--%H-%M`] Remove folder."
    rm -rf $DATADIR/$PREFIX
    if [[ $? -gt 0 ]];then
    echo "[----------][`date +%F--%H-%M`] Remove folder failed."
    exit
    fi
    echo "[++++++++--][`date +%F--%H-%M`] Remove folder finished."
    echo "[+++++++++-][`date +%F--%H-%M`] Start datadir space (USED): `du -h $DATADIR | tail -n1`"
    echo "[++++++++++][`date +%F--%H-%M`] Free HDD space: `df -h /home|tail -n1|awk '{print $4}'`"
    echo "[+SUCCESS!+][`date +%F--%H-%M`] All operations completed successfully!"
    exit 0 

    3) And add this line into crontab. Backups will be created each morning at 6am.

    0 6 * * * cd /backup/ && sh backup.sh

     

    Regards.

     

    Is this work on FreeBSD ? Thanks.

  2.  

     if (!(empty($_GET['s'])) || empty($_GET['w'])) {
      $p_name = "pages";
      $v_name = "s";
     } else {
      $p_name = "wiki";
      $v_name = "w";
     }
     
     $includeDir = ".". DIRECTORY_SEPARATOR .$p_name. DIRECTORY_SEPARATOR;
     $includeDefault = $includeDir . "home.php";
     
     if (isset($_GET[$v_name]) && !empty($_GET[$v_name]))
     {
      $_GET[$v_name] = str_replace("0", '', $_GET[$v_name]);
      $includeFile = basename(realpath($includeDir . $_GET[$v_name] . ".php"));
      $includePath = $includeDir . $includeFile;
      if (!empty($includeFile) && file_exists($includePath))
      {
       include ($includePath);
      } else {
       include ($includeDefault);
      }
     } else {
      include ($includeDefault);
     }
    
    

     

     

    Thank you very much for you help. It is working very well. :)

×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.