Move BT_backup folder to linux

Linux specific questions, problems.
Post Reply
Penn

Move BT_backup folder to linux

Post by Penn »

I want to move to Linux but I have no way of migrating my 500+ torrents like I don whenever I upgrade window. Is there another way to this without me having to add the torrents one after another  :-\
ciaobaby

Re: Move BT_backup folder to linux

Post by ciaobaby »

Move BT_backup folder to linux
Probably not going to work, as Linux does NOT use "drive letters" to identify a particular filing system or "drive" location.

If you have incomplete tasks running turn OFF the additional extension, check this is complete, then pause all tasks before closing down the windows client.

Configure the Linux client with save locations, set "Do not start the download automatically"  then set a "watch folder", place the payloads in the 'completed' location then drop all the .torrent files from BT_Backup in to the watch folder.

Make sure that you have a backup copy of the payloads just in case, then once the "auto load" is complete, do some 'test starts" of tasks by running a force recheck first then resuming if the recheck completes satisfactorily). If they work it should be safe enough to recheck and start them all.
grasmanek94

Re: Move BT_backup folder to linux

Post by grasmanek94 »

So I had the same issue, here's how I approached it:

0) Re-create all your categories you have on Windows, on the Linux qBittorrent client
1) shutdown qbt on all your machines (both windows and linux)
2) transfer all torrent DATA FILES and KEEP THE SAME FILE STRUCTURE (from windows to linux)
e.g. I had everything in V:\downloads and U:\downloads and transfered everything to /data/torrents/downloads
3) Download Visual Studio Express and create a new C# Console Application (name of the project must be qBTConverter) and paste this source code (I made this, you can also run this with mono on linux, should work):

Code: Select all

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace qBTConverter
{
    class Program
    {
        static bool Match(ref byte[] data, ref byte[] search, int data_index)
        {
            if(data.Length <= data_index + search.Length)
            {
                return false;
            }
            
            for(int i = 0; i < search.Length; ++i)
            {
                if(data[data_index + i] != search[i])
                {
                    return false;
                }
            }

            return true;
        }

        static int Position(ref byte[] data, string find_what, int start_pos = 0)
        {
            byte[] search = Encoding.UTF8.GetBytes(find_what);

            for (int i = start_pos; i < (data.Length - search.Length); ++i)
            {
                if(Match(ref data, ref search, i))
                {
                    return i;
                }
            }
            return -1;
        }

        static byte[] Extract(ref byte[] data, int start, int end)
        {
            int size = end - start;
            if(size < 0)
            {
                return null;
            }

            byte[] buffer = new byte[size];
            for(int i = 0; i < size; ++i)
            {
                buffer[i] = data[start + i];
            }
            return buffer;
        }

        public static byte[] Combine(byte[] first, byte[] second, byte[] third)
        {
            byte[] ret = new byte[first.Length + second.Length + third.Length];
            Buffer.BlockCopy(first, 0, ret, 0, first.Length);
            Buffer.BlockCopy(second, 0, ret, first.Length, second.Length);
            Buffer.BlockCopy(third, 0, ret, first.Length + second.Length, third.Length);
            return ret;
        }

        static byte[] ReplaceBytes(ref byte[] data, int from, int to, byte[] with)
        {
            byte[] first = data.Take(from).ToArray();
            byte[] second = data.Skip(to).Take(data.Length - to).ToArray();

            return Combine(first, with, second);
        }

        static bool Replace(ref byte[] data, string which, string location, string replace)
        {
            int pos_a = Position(ref data, which);
            if(pos_a == -1)
            {
                return false;
            }

            int pos_b = pos_a + Encoding.UTF8.GetBytes(which).Length;
            int pos_c = Position(ref data, ":", pos_b);

            byte[] b_len = Extract(ref data, pos_b, pos_c);
            int len = Int32.Parse(Encoding.UTF8.GetString(b_len));

            byte[] b_path = Extract(ref data, pos_c + 1, pos_c + len + 1);
            string path = Encoding.UTF8.GetString(b_path);

            if(path.IndexOf(location) == -1)
            {
                return false;
            }

            path = path.Replace(location, replace).Replace("\\", "/");

            byte[] r_path = Encoding.UTF8.GetBytes(path.Length.ToString() + ":" + path);

            data = ReplaceBytes(ref data, pos_b, pos_c + len + 1, r_path);
            return true;
        }

        // :qBt-savePath<len>:<len chars>
        // :save_path<len>:<len chars>
        static void Main(string[] args)
        {
            if(args.Length < 3)
            {
                Console.WriteLine("Usage: qBTConverter <path> <windows base directory> <linux base directory>");
                return;
            }

            if(args[0][args[0].Length-1] == '\\')
            {
                args[0].Remove(args[0].Length - 1);
            }

            Console.WriteLine("Using path \"" + args[0] + "\"");
            Console.WriteLine("Search \"" + args[1] + "\"");
            Console.WriteLine("Replace \"" + args[2] + "\" & \\ -> /");

            string[] files =
                Directory.GetFiles(args[0], "*.fastresume", SearchOption.TopDirectoryOnly);

            if (files.Length < 1)
            {
                Console.WriteLine("No .fastresume files found in path");
                return;
            }

            Console.WriteLine("Found " + files.Length.ToString() + " fastresume files");

            string outpath = args[0] + "\\out";

            System.IO.Directory.CreateDirectory(outpath);
            Console.WriteLine("Outputting results to \"" + outpath + "\"");

            int files_updated = 0;
            int total_occurences = 0;
            foreach (string file in files)
            {
                Console.WriteLine("Processing \"" + file + "\"...");
                byte[] data = File.ReadAllBytes(file);
                string out_file = file.Replace(args[0], outpath);
                Console.WriteLine("\tSaving results to \"" + out_file + "\"...");

                int occurences_replaced = 0;
                while(Replace(ref data, ":qBt-savePath", args[1], args[2]))
                {
                    ++occurences_replaced;
                }

                while (Replace(ref data, ":save_path", args[1], args[2]))
                {
                    ++occurences_replaced;
                }

                if (occurences_replaced > 0)
                {
                    File.WriteAllBytes(out_file, data);
                    ++files_updated;
                    total_occurences += occurences_replaced;
                    Console.WriteLine("\tDone, replaced " + occurences_replaced.ToString() + " occurences");
                }
            }

            Console.WriteLine("Updated " + files_updated.ToString() + " files and " + total_occurences + " total occurences");
        }
    }
}
4) Compile it (Build Solution), you should find a .exe in your project folder
5) Open a command prompt in the folder with the .exe
6) Issue the command (once for each download folder!)

Code: Select all

qBTConvert.exe C:\Users\<YourUser>\AppData\Local\qBittorrent\BT_backup <your windows download directory without \ at the end> <your linux download directory without / at the end>
e.g.:

Code: Select all

qBTConvert.exe C:\Users\grasmanek94\AppData\Local\qBittorrent\BT_backup V:\downloads /data/torrents/downloads
qBTConvert.exe C:\Users\grasmanek94\AppData\Local\qBittorrent\BT_backup U:\downloads /data/torrents/downloads
7) Move everything in C:\Users\<your user>\AppData\Local\qBittorrent\BT_backup\out to /home/<your linux qbittorrent user>/.local/share/data/qBittorrent/BT_backup
8 ) Copy all torrent files from C:\Users\<your user>\AppData\Local\qBittorrent\BT_backup to /home/<your linux qbittorrent user>/.local/share/data/qBittorrent/BT_backup
9) Start qBittorrent on Linux, everything should be back like it was, remember to recreate any categories before you do all these steps!
10) That's it, no need to recheck your torrents
Attachments

[The extension has been deactivated and can no longer be displayed.]

Last edited by grasmanek94 on Tue Feb 06, 2018 7:03 pm, edited 1 time in total.
Mike_EE

Re: Move BT_backup folder to linux

Post by Mike_EE »

grasmanek94 -

Thank you for taking the time to create and post this. I tried building in VSE2017, but the CLI input arguments set build errors and it won't compile.
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'Directory' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 126 N/A
Error CS0103 The name 'SearchOption' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 126 N/A
Error CS0103 The name 'File' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 146 N/A
Error CS0103 The name 'File' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 163 N/A
Any fix?
grasmanek94

Re: Move BT_backup folder to linux

Post by grasmanek94 »

Mike_EE wrote: grasmanek94 -

Thank you for taking the time to create and post this. I tried building in VSE2017, but the CLI input arguments set build errors and it won't compile.
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'Directory' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 126 N/A
Error CS0103 The name 'SearchOption' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 126 N/A
Error CS0103 The name 'File' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 146 N/A
Error CS0103 The name 'File' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 163 N/A
Any fix?
I think you might be trying to create an UWP app, which would cause the issue because the UWP SDK doesn't allow direct drive access.

What you should do is:

New > Project.. > Visual C# > Console App (.NET Framework) > qBTConverter > Uncheck "create directory for solution" > OK

That worked for me on VS2017
Mike_EE

Re: Move BT_backup folder to linux

Post by Mike_EE »

grasmanek94 wrote:
Mike_EE wrote: grasmanek94 -

Thank you for taking the time to create and post this. I tried building in VSE2017, but the CLI input arguments set build errors and it won't compile.
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'Directory' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 126 N/A
Error CS0103 The name 'SearchOption' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 126 N/A
Error CS0103 The name 'File' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 146 N/A
Error CS0103 The name 'File' does not exist in the current context qBTConverter C:\Users\Mxxxxxr\source\repos\qBTConverter\qBTConverter\Program.cs 163 N/A
Any fix?
I think you might be trying to create an UWP app, which would cause the issue because the UWP SDK doesn't allow direct drive access.

What you should do is:

New > Project.. > Visual C# > Console App (.NET Framework) > qBTConverter > Uncheck "create directory for solution" > OK

That worked for me on VS2017
I started from scratch and followed your directions precisely, still have the same errors.

UPDATE:  I appended System.IO to the file operations and it compiled correctly. I'll try it tonight and report back.

Again, thanks grasmanek94 for the work.
Mike_EE

Re: Move BT_backup folder to linux

Post by Mike_EE »

grasmanek94  -

I tried this against 500 torrents and the result was "updated 0 files and 0 total occurrences". Any thoughts?

Thanks!
AlexP11223

Re: Move BT_backup folder to linux

Post by AlexP11223 »

Worked fine for me, thank you.

I published the project here https://github.com/AlexP11223/qBTConverter so you don't have to create VS project etc. yourself, just download using the button on the right side and open the .sln file. There is also my .exe on the Releases page.

Also added a bit more output.
Last edited by AlexP11223 on Sat Sep 29, 2018 8:44 pm, edited 1 time in total.
postcd
Member
Member
Posts: 74
Joined: Wed Feb 24, 2016 11:25 am

Re: Move BT_backup folder to linux

Post by postcd »

One can also resign on migration and use Windows qbittorrent on Linux via app called Wine.
Post Reply