My VPS is running on Centos 7 with nginx and MySQL 8.0 I have created 2 cron jobs to backup my files and database everyday at a specific time. everything works fine but I'm trying to send those backup files to my backup host. I created a bash file to automatically send files over backup host, but the problem is, it sends ALL the Tar files to the remote destination, and what I want, is to send only the newly created file to be uploaded each time and do the same routine for the last 7 files (weekly cycle). I ran in to problems and I was told it's better to make the cron job do all the work. Is it possible to tell the cron command, when done creating Tar file (for both sql and files), send them to backup host, and only keep 7 backups by replacing the old one? here is my bash script:
#!/bin/bash
ftp=****
username=****
passwd=****
remote=/DESTINATION on Backup Host/
folder=$1
cd /local folder to pick files/$folder
pwd
ftp -n -i $ftp <<EOF
user $username $passwd
mkdir $remote/$folder
cd $remote/$folder
mput *
close
EOF
and here is my cron job:
00 01 * * * mysqldump -u "location_to_username_and_password" "db name" | gzip -c > /location/db_name.`date +\%a\-\%Y\.\%m\.\%d`.sql.gz
00 03 * * * tar -cvpzf /location/db_name.`date +\%a\-\%Y\.\%m\.\%d`.tar.gz -C /route_to_folder/ folder_name