Recursive delete via SSH->FTP->NAS

Venezia

Verified User
Joined
Nov 29, 2005
Messages
9
I have installed a 200gb NAS device to a server running CENTOS. Each night the control panel ( in this case DirectAdmin) backs up onto the NAS.

To access the NAS files, I currently login to the server via SSH and then access the NAS via FTP from the shell.

As the NAS fills up, I need to delete old backups.

The DirectAdmin control panel stores each backup in a directory named by creation date. Inside each directory is a tree of directories and compressed files.

FTP has no support for recursive delete of these backup directories. So to delete old backups and make space I have to navigate to each sub dir and delete the files. Very time consuming and not all practical.

Can anyone suggest a sane way to recursively delete these old backups via FTP?

I know it's not a DA related issue, but I thought that someone in the system forum might have been down this track before and know of a solution.

Thanks
Venezia
 
You can use this script I made a while back which I run on a crontab.

Code:
#!/bin/sh

backup_directory="/backup/system" # No trailing /
backup_time="5" # Remove backups how many days old? Number variable only!

#### Commands ####

find_files=`find $backup_directory -maxdepth +1 -mtime +$backup_time`

#### Begin Script ####

ver="Directory cleaner and backup v1.0 by Andrew ([email protected])"

##

echo "
/*

GENERAL SCRIPT INFORMATION:

Below is the output of this crontab or automated script. This is an
automated script only, do not reply to the system as your mail will be
purged.

This is debug information from the output of: /sbin/server-backup.sh

This script is used to delete/purge the old backups out of the /backup folder.
All content older then that set with the variable $backup_time will be lost.

This script was designed for FreeBSD 5.4 and later.

This script is copyright 2005 Andrewk.net.

*/
"
echo ""
echo "Looking for old backups... Older then $backup_time days old."
echo "----"
if [ -z "$find_files" ]; then                 
echo "None Found!"
else
echo "$find_files"
fi
echo "----"
echo ""
echo "If any folders were found they have deleted."
find $backup_directory -mtime +$backup_time -delete
echo ""
echo "Done."
echo ""
echo "Thanks for using $ver."
echo ""

You just edit the backup_directory variable and then the amount of days variable.

Chmod it executable
 
May be I got it all wrong, but it looks like the script above should be executed on NAS (which is currently accessible via FTP only, right?).

If it's possible to SSH into NAS, deleting old backups is as easy as executing rm -rf command, no script is actually needed :)

I would consider mounting NAS via NFS or even SMB (depending on what your other servers are running).
 
Webcart said:
May be I got it all wrong, but it looks like the script above should be executed on NAS (which is currently accessible via FTP only, right?).

If it's possible to SSH into NAS, deleting old backups is as easy as executing rm -rf command, no script is actually needed :)

I would consider mounting NAS via NFS or even SMB (depending on what your other servers are running).

A script is needed if he wants it done automatically by amount of days old. :)
 
chatwizrd said:
A script is needed if he wants it done automatically by amount of days old. :)

That's correct, but it assumes the backups can be accesssed locally at /backup/system which doesn't solve the problem raised here because NAS is only accessible via FTP atm, right?
 
Webcart said:
That's correct, but it assumes the backups can be accesssed locally at /backup/system which doesn't solve the problem raised here because NAS is only accessible via FTP atm, right?

It matters what kind of server it actually is. If ftp is the only way to login to it then he would have to find some way to test the files on the remote machine for dates.

It also matters what kind of NAS it actually is. If its another machine of his that he has linux then this solution would work. If it is just a ftp account that he was given then it wouldnt work so well and he would have to design some sort of program that could test for date. If it is a true NAS device it would matter on its management features.
 
Last edited:
Turned out the solution for me was to use

ncftp

which supports recursive delete and a whole bunch of other stuff ideally suited to managing these sorts of devices. Worth a look for anyone interested.

It was already bundled on the server. Apparently exists in many packages.

http://www.ncftp.com
 
Last edited:
Back
Top