Article

  • 9 years

    4 months

    YetiShare / Core

    6592

How to move uploaded files from one server to another in bulk

To move ALL uploaded files from one server to another do this manually.

  • Setup your new file server and test it's uploading and downloading files fine.
  • Make note of the new server 'id' from your database. It's in the 'file_server' table.
  • Backup your database.
  • Copy or move all files from your old server (in files/) to your new server. Ensure you keep the subfolders and same filenames. For local or "direct" storage, we recommend using rsync to do this if you have a lot of files. i.e:
Via root SSH on your current server, execute the following command. Replace the paths and server IP address:

rsync -avh --progress /current/server/path/to/webroot/files/ root@new_server_ip:/new/server/path/to/webroot/files/

For example:

rsync -avh --progress /home/admin/web/yourdomain.com/public_html/files/ [email protected]:/home/admin/web/yourdomain.com/public_html/files

  • For other storage servers such as S3 or Wasabi, you can use a Windows tool such as S3Browser or a Linux CLI tool like s3cmd.
  • Update the file_server_id on all file_artifact_storage records in your database to point at the new server. Below, replace NEW_SERVER_ID with your new server id (noted above) and OLD_SERVER_ID with your old server id.
UPDATE file_artifact_storage SET file_server_id = NEW_SERVER_ID WHERE file_server_id = OLD_SERVER_ID;
All your files should now work as they did before but from the new server. Once you've confirmed everything is working, you can remove the old server record in 'file_server' via the database.

How to move a Single File to/from FTP Storage

  • Open your database via phpMyAdmin or similar.
  • Within the file_server table, make note of the id of the new file server.
  • Locate the file_artifact record within the 'file' table. You can use the file's short url within the query like below (replace 'sUJ' with the short url):
SELECT local_file_path FROM file_artifact WHERE file_id IN (SELECT id FROM file WHERE shortUrl = 'sUJ');

  • The 'local_file_path' will show where the file is stored on it's current server. Move the actual file to your new server. Add the sub-folder if it doesn't already exist. So you'll end up with something like: [server]/e0/e069a959a257fb49ccaaabaf029f0c2d
  • Within the database, update the file_server_id in the 'file_artifact_storage' table record with the new server 'id' you noted above. Example "update" query (replace 'sUJ', NEW_SERVER_ID & OLD_SERVER_ID):
UPDATE file_artifact_storage SET file_server_id = NEW_SERVER_ID WHERE file_server_id = OLD_SERVER_ID AND file_artifact_id IN (SELECT id FROM file_artifact WHERE file_id IN (SELECT id FROM file WHERE shortUrl = 'sUJ'));