Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So I can do this: sftp user@server

These are the files https://gist.github.com/438a6b82aff3064a19c9

i need to delete files older than 60 days.

Any way to automate this?

find command doesn't work. deleting by wildcard doesn't work.

Rsync is supported. How is it done with rsync?

share|improve this question

3 Answers 3

As an alternative to the better options above you could script (using lftp or something) to delete all files using a wildcard and a local date substiatution.

It's very ugly but it works:

for i in 60 999; do lftp sftp://user@host -c "rm /path/to/website_production_$(date -d "$i days ago" +%m-%d-%Y)*" done

You might want to set it up so you don't have to enter the password.

share|improve this answer
    
i think this is the right answer. will add to my shell script, thanks. –  kgpdeveloper Jul 5 '10 at 6:52

Mount the sftp folder on your system, if you are using OS X you can use Transmit to do that or Linux (Ubuntu in this case) you can use this guide http://blog.damontimm.com/how-to-mount-a-sftp-folder-ssh-ftp-on-ubuntu-linux-using-sshfs-fuse/ .

They all use FuSE, so I bet it also works in Windows as well if you look it up. But once you have it mounted you should be able to use any commands you can natively on your system.

share|improve this answer

Rsync protects date of creation. So you can rsync all files to your computer. Then run find to select files older than 60 days and delete them. And upload them back via rsync. Or just delete them in destination.

EDIT

Result of rsync test on local directories:

rsync -av input/ tmp/
find tmp/* -mtime +10 -exec rm {} \;
rsync --delete -av tmp/ input

After this, directory ./input/ is stripped from files modified more then 10 days ago. This should be appliable on remote directory via SFTP.

share|improve this answer
    
i see. that's not too easy :/ –  kgpdeveloper May 20 '10 at 6:50
    
It's not hard, he gave you the exact commands. Replace "input" with sftp://youruser@theserver:/pathname –  Joris Jul 2 '10 at 4:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.