skip to Main Content

I have a server(centOS) with plesk installed and I need to planning some backups for each day.
Plesk allows only one planned backup, so I created this solution:

  1. Create every night a backup inside a folder
  2. Launch a script that will read the day from the title of a txt file inside the folder (launched every night via cronTAB)
  3. Move the backup file inside the correct directoy (based on the name of the day)
  4. Change the name of the day in the title of the txt

This is my script (not tested right now):

BACKUPNAME="backupname"
cd /backup/daily
find . -type f | while IFS= read filename; do
  case "${filename,,*}" in 
    mon.txt) mv $BACKUPNAME ../mon
    mv mon.txt tue.txt;;
    tue.txt) mv $BACKUPNAME ../tue
    mv tue.txt wed.txt;;
    wed.txt) mv $BACKUPNAME ../wed
    mv wed.txt thu.txt;;
    thu.txt) mv $BACKUPNAME ../thu
    mv thu.txt fri.txt;;
    fri.txt) mv $BACKUPNAME ../fri
    mv fri.txt sat.txt;;
    sat.txt) mv $BACKUPNAME ../sat
    mv sat.txt sun.txt;;
    sun.txt) mv $BACKUPNAME ../sun
    mv sun.txt mon.txt;;
    * : ;; #nothing
  esac
done

Do you think is it a good/stable solution?

Thanks!

2

Answers


  1. I don’t know what you mean with “only one planned backup”, could you explain this?

    On the other hand, why not doing an rsync and deleting the oldest ones if needed… This is how I do this:

    #!/bin/bash
    date=`/bin/date "+%Y-%m-%dT%H_%M_%S"`
    HOME=/root
    
    /bin/echo -e "nn# Backup from $daten" >> /var/log/backup.log
    
    /usr/bin/rsync -axzP 
      --delete 
      --delete-excluded 
      --exclude-from=$HOME/.rsync/exclude 
      --link-dest=/COREBACKUP/CurrentBackup 
      / /COREBACKUP/Backups/incomplete_back-$date >> /var/log/backup.log 2>&1 
    && mv /COREBACKUP/Backups/incomplete_back-$date /COREBACKUP/Backups/back-$date 
    && rm -f /COREBACKUP/CurrentBackup 
    && ln -s /COREBACKUP/Backups/back-$date /COREBACKUP/CurrentBackup 
    && echo `/bin/date "+%Y-%m-%d - %H:%M:%S"` > /var/log/lastbackup.log 2>&1
    

    This script is called every day via cron, and it makes a full backup of “/” excluding everything listed in $HOME/.rsync/exclude.

    The backups are stored in /COREBACKUP/Backups/back-$date, the latest backup is stored in /COREBACKUP/CurrentBackup.

    It works fine, although it could’ve been written more user friendly 😉

    Login or Signup to reply.
  2. Rotating the backup destination depending on day is reasonable, but the name-generation method shown in the question depends on the system running once daily. If the system were shut down for a day, or if the script ran twice in a day, your mon.txt, tue.txt, … sequence would go out of sync. Instead of using a filename and a clunky case statement to get the name of the destination directory, use code like the following:

    day=$(date +%a)
    mv $BACKUPNAME ../${day,,}
    

    If the backup file belongs to a different day than current, use a date form like one of the following, which respectively set day to the name of yesterday, or to the name of the day when the file was last modified.

    day=$(date +%a --date=yesterday)
    day=$(date +%a -r $BACKUPNAME)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search