0

I have a shell / bash that works perfectly for making backups script, the problem is that I have large files that are giving problems running the script. The script has q compress the file in tar.gz format and it does it, but when it comes in 6GB + or the script continues compressing the file but it goes in the next lines and backups is failed, the server must have a set_time_limit; equal in php, the php file that calls the shell / bash I use set_time_limit (0); and works very well, the shell / bash has something too?

The script:

MYSQLDUMP="$(which mysqldump)"
$MYSQLDUMP -u $DBUSER -h $DBHOST -p$DBPASS $DBNAME | gzip > $TIMESTAMP.sql.gz

ssh $USER_SSH@$HOST_SSH "tar -zcf - $HOME" > $TIMESTAMP.backup.tar.gz

tar -zcf $TIMESTAMP.tar.gz $TIMESTAMP.backup.tar.gz $TIMESTAMP.sql.gz

SUCCESS=$?

rm $TIMESTAMP.sql.gz
rm $TIMESTAMP.backup.tar.gz

I did not post the variables because I think it is not necessary

Before he finished tar it removes the 2 files with the final lines ... if the file is less than about 6GB or 7GB it does not happen this

2
  • You tagged the question with bash & shell only. Do you have a reason to believe there is a problem with the script alone? Because if not, you should explain more how the script is invoked, and use other tags, such as php. Aug 10, 2016 at 2:34
  • I don't see anything wrong with the script. Minor things: $HOME will be expanded locally not remotely, but this doesn't explain the problem. The only thing I would check is that there is no unusual setting of RequestTTY in .ssh/config: yes or force would be bad here. Aug 10, 2016 at 2:40

1 Answer 1

0

First it would be handy to know how you are invoking your php script. Secondly, instead of having the php script do the mysql dump, you can have your bash/shell script do it and all your php script does is invokes it.

Now since you have your php script connecting to mysql, what you could do with the minimal modification to your current script. Instead of having your php script wait on the bash script. Just have php invoke the bash script and forget about it this way you don't have to worry how long it takes.

In your bash script, have it update a row in mysql saying it was successful or failed after its done compressing and if you have your bash script do the dump it would be more secure than having a php script doing it IE, your credentials for the DB won't ever be accessible via the web as well as I recommend generating a private key for ssh for php as well. Then you could just make php check on it later with a different script and then do some other things like report it visually that it was successful etc. by checking the DB for the results.

There is many different ways you can solve this, from using PHP with few different scripts, to using bash to do more things, to even including other languages like javascript to aide in dynamically updating your page for the results so you don't have to refresh etc etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .