todiadiyatmo / bash-backup-rotation-script Goto Github PK
View Code? Open in Web Editor NEWBash backup rotation script for your files / website
License: MIT License
Bash backup rotation script for your files / website
License: MIT License
Hi,
Good work this script !
But little bug with DEST_DIR="$DEST_BASE_DIR/$HOST/$DATABASE".
backup.sh:33
mkdir: cannot create directory '/thebasedir/localhost/mydatabase': No such file or directory.
backup_rotation.sh, line 397
echo "mkdir $FTP_TARGET_DIR" >> $TMP_DIR/backup.incoming/ftp_command.tmp
The exection of this ftp script say me that it cant create the dir, because there is 3 (or 2) directory to create. FTP seems only works with 1 directory to create.
Bisous.
Keep getting mails like:
/backupdav/18-08-2016-daily.data.tar.xz does not seem to exist. Something failed.
When it run as cron, works if i run it manual.
Hi, firstly thanks for writing this script!
I have the following issue while trying to get the file to send via FTP:
'Using binary mode to transfer files.
550 Can't create directory: File exists
250 OK. Current directory is /backups
200 TYPE is now 8-bit binary
local: /home/backup/backup.incoming/04-05-2015-daily.tgz remote: .
200 PORT command successful
553 Can't open that file: Is a directory
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.'
Thanks
After setting up the configuration file and running the script, I get the following error:
root@kraken:~/backups# bash backup_rotation.sh
Removing expired backups...
Creating backup dir..
Copy backup to local dir..
mv: cannot stat `/tmp/backup.incoming/*': No such file or directory
Finish..
However the directory does exist:
root@kraken:~/backups# ls -ahl /tmp/backup.incoming/
total 8.0K
drwxr-xr-x 2 root root 4.0K Dec 1 16:30 .
drwxrwxrwt 9 root root 4.0K Dec 1 16:30 ..
Any idea what could be happening
The mysqldump command is missing -h $DBHOST
# The directory to be backup , DO NOT END THE DIRECTORY WITH BACKSLASH !
TARGET_DIR=/target_directory
# The backup directory , DO NOT END THE DIRECTORY WITH BACKSLASH !
BACKUP_DIR=/copy_target_to_backup_directory
I think these are hard to understand. I would normally think the target directory should be where you want the files to go, and the backup directory to be the files that are being backed up.
Switching them and adding some extra words would make more sense:
# The directory where the files to be backed up are located DO NOT END THE DIRECTORY WITH BACKSLASH !
BACKUP_DIR=/backup_directory
# The directory where the backups are sent , DO NOT END THE DIRECTORY WITH BACKSLASH !
TARGET_DIR=/copy_backup_directory_to_here
Note: you will have to go through the script and switch them as well. It's not that many though.
You could test if LZMA is supported
Thank you so much for the code, it's perfect for what I needed.
Just a small improvement, I added a $DBHOST and $OPTIONS to the mysqldump ($OPTIONS in my case --column-statistics=0)
In case you want to keep it in mind
Thank you very much.
Greetings
Hi thanks for your script but I get this error:
# sh backup_rotation.sh
backup_rotation.sh: 124: backup_rotation.sh: [[: not found
backup_rotation.sh: 128: backup_rotation.sh: [[: not found
mkdir: cannot create directory `/home/backup': File exists
Regards
The local_remote function names the output file as mysql but the other functions name the output file as just "sql". This means that the "grep mysql" in the other functions won't find anything to delete. In my version I have normalised this so that all files are names "sql" and all searches also use "sql". I don't know if this repo is still being maintained but in case this helps anyone.
This section of code is incorrect
find $TMP_DIR/ -maxdepth 1 -mtime +$RETENTION_DAY_LOOKUP -name "$BACKUP_TYPE" -exec rm -rv {} ;
find $TMP_DIR/.ftp_cache/ -maxdepth 1 -mtime +$RETENTION_DAY_LOOKUP -name "$BACKUP_TYPE" -exec rm -rv {} ;
Hi,
In fact, in your server, you can have multiple sites (or directories) without sql database, a web site with 2 or 3 databases.
So, in this case, a better backup.conf can be with separate DB and FTP.
/Nico
Using Ubuntu 14.04 and vsftpd on both systems.
$ vsftpd -v
$ vsftpd: version 3.0.2
I keep getting the following error:
local: /tmp/backup.incoming/27-01-2016-daily.sql.tar.xz remote: dcim_backup_opendcim/27-01-2016-daily.sql.tar.xz
200 PORT command successful. Consider using PASV.
553 Could not create file.
So I found a simple change that fixes it, YMMV of course. This works for me.
-echo "put $TMP_DIR/backup.incoming/$backup_filename $FTP_TARGET_DIR/$backup_filename" >> $TMP_DIR/backup.incoming/ftp_command.tmp
+echo "put $TMP_DIR/backup.incoming/$backup_filename $backup_filename" >> $TMP_DIR/backup.incoming/ftp_command.tmp
-echo "put $TMP_DIR/backup.incoming/$backup_filename_sql $FTP_TARGET_DIR/$backup_filename_sql" >> $TMP_DIR/backup.incoming/ftp_command.tmp
+echo "put $TMP_DIR/backup.incoming/$backup_filename_sql $backup_filename_sql" >> $TMP_DIR/backup.incoming/ftp_command.tmp
Using this option set:
LOCAL_BACKUP_OPTION=1
FTP_BACKUP_OPTION=0
SQL_BACKUP_OPTION=0
FILES_BACKUP_OPTION=7
Script will give incorrect error due to this code (it's not really optional, it's happening always):
if [ ! -f $TMP_DIR/backup.incoming/$backup_filename ]; then
echo "Daily backup failed! Please check for missing files." | mail -s "$EMAIL_SUBJECT_TAG Backup Failed" $MAIL
fi
One possible fix is to only check for back-up file name when SQL backup option is set to non-zero? We are using script for CouchDB backup so we used this for temporary fix:
if [ ! $PERFORM_SQL_BACKUP -eq 0 ]; then
if [ ! -f $TMP_DIR/backup.incoming/$backup_filename ]; then
echo "Daily backup failed! Please check for missing files." | mail -s "$EMAIL_SUBJECT_TAG Backup Failed" $MAIL
fi
fi
The script should check the value of LOCAL_BACKUP_OPTION before executing "Cleanup expired backups", "Perform Files Backup" and "Optional check if source files exist. Email if failed." I have disabled local backup and use only FTP backup, so I'm getting error messages about the missing local target directory and email about "Finished, but failed".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.