Backup Files on Google Colab with Cron Job | ATLASSC.NET
Skip to main content
/// .DATA.FRAGMENT_20230521

Backup Files on Google Colab with Cron Job

1 minAuthor: Z.SHINCHVEN

Google Colab is a great tool for machine learning. However, the virtual machine will be recycled once AFK for a while. If you don't save your files, you will lose them.

I've lost my files several times. So I decided to write a script to backup my files to Google Drive.

Auto file backup can be done with cron job. Here's the code snippet:

# mount google drive
from google.colab import drive
drive.mount('/content/drive')

# install cron job
!apt-get install cron

# create a script to zip the files to the drive
!touch zip_file.sh
!echo "#!/bin/bash" >> /content/zip_file.sh
!echo 'cd <FOLDER_TO_BACKUP> && zip -r /content/drive/MyDrive/file_$(date +%Y-%m-%d).zip ./' >> /content/zip_file.sh

# add execution permission
!chmod +x /content/zip_file.sh

# create a cron job to run the script every 10 minutes
!echo "*/10 * * * * /bin/bash /content/zip_file.sh" | crontab -

# start cron job
!service cron start
RackNerd Billboard Banner
Share node:
/// .RELATED.DATA_STREAMSShared tags

Related posts

Scanning_database_for_correlations…

/// .UPLINK.SUBSCRIBE

Keep your deck synced with every new transmission from ATLASSC.NET. Subscribe over RSS or Atom, or wire the whole archive straight into your AI assistant with the MCP server.