skip to Main Content

I am new to Linux. I am using CentOS 7. I found out that my new backup always replace my old backups. For example, backup on 15th of July 2019 will replace backup on 14th of July 2019.

# Create archive filename.
#day=$(date +%A)
day=$(date -d "$D" '+%d')
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"

Could you point out what am I doing wrong with this command? Or could there
possibly be another reason that my backups would replace my old one that I did not see? Any help would be appreciated.

2

Answers


  1. I don’t find any issue in the code but using just a combination of hostname + day as a key identifier to your filename is not unique and will replace the backup file last month.

    And also there might be some other process that is removing the backup file like if you have log retention policy in the directory from where you store the backup.

    Login or Signup to reply.
  2. Use a date, hour / minute in the name of your archive so it wont replace your old backup.

    day = $(date +%F %l:%M)"

    Adding all the fields (day, date, time and year) will help you to store all backups without overwriting any.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search